failing auto complete test (#1578)

This commit is contained in:
Kurt Hutten
2024-03-02 03:22:04 +11:00
committed by GitHub
parent cc0d601294
commit e4c5fad8c7
4 changed files with 34 additions and 17 deletions

View File

@ -386,12 +386,16 @@ test('Auto complete works', async ({ page }) => {
await page.keyboard.press('ArrowDown')
await page.keyboard.press('ArrowDown')
await page.keyboard.press('Enter')
await page.keyboard.type('(5, %)')
// finish line with comment
await page.keyboard.type('(5, %) // lin')
await page.waitForTimeout(100)
// there shouldn't be any auto complete options for 'lin' in the comment
await expect(page.locator('.cm-completionLabel')).not.toBeVisible()
await expect(page.locator('.cm-content'))
.toHaveText(`const part001 = startSketchOn('XY')
|> startProfileAt([0,0], %)
|> xLine(5, %)`)
|> xLine(5, %) // lin`)
})
// Onboarding tests
@ -699,6 +703,8 @@ test('Can extrude from the command bar', async ({ page, context }) => {
).toBeDisabled()
await page.keyboard.press('Enter')
await expect(page.getByText('Confirm Extrude')).toBeVisible()
// Check that the code was updated
await page.keyboard.press('Enter')
// Unfortunately this indentation seems to matter for the test
@ -930,7 +936,7 @@ fn yohey = (pos) => {
|> line([-15.79, 17.08], %)
return ''
}
yohey([15.79, -34.6])
`
)

View File

@ -4,6 +4,7 @@ import { ViewPlugin, hoverTooltip, tooltips } from '@codemirror/view'
import { CompletionTriggerKind } from 'vscode-languageserver-protocol'
import { offsetToPos } from 'editor/plugins/lsp/util'
import { LanguageServerOptions } from 'editor/plugins/lsp'
import { syntaxTree } from '@codemirror/language'
import {
LanguageServerPlugin,
documentUri,
@ -40,6 +41,14 @@ export function kclPlugin(options: LanguageServerOptions): Extension {
if (plugin == null) return null
const { state, pos, explicit } = context
let nodeBefore = syntaxTree(state).resolveInner(pos, -1)
if (
nodeBefore.name === 'BlockComment' ||
nodeBefore.name === 'LineComment'
)
return null
const line = state.doc.lineAt(pos)
let trigKind: CompletionTriggerKind = CompletionTriggerKind.Invoked
let trigChar: string | undefined
@ -60,6 +69,7 @@ export function kclPlugin(options: LanguageServerOptions): Extension {
) {
return null
}
return await plugin.requestCompletion(
context,
offsetToPos(state.doc, pos),

View File

@ -3648,6 +3648,21 @@ const cylinder = startSketchOn('-XZ')
assert!(value.is_some());
}
#[test]
fn test_ast_get_non_code_node_inline_comment() {
let some_program_string = r#"const part001 = startSketchOn('XY')
|> startProfileAt([0,0], %)
|> xLine(5, %) // lin
"#;
let tokens = crate::token::lexer(some_program_string);
let parser = crate::parser::Parser::new(tokens);
let program = parser.ast().unwrap();
let value = program.get_non_code_meta_for_position(86);
assert!(value.is_some());
}
#[test]
fn test_recast_negative_var() {
let some_program_string = r#"const w = 20

View File

@ -430,20 +430,6 @@ impl LanguageServer for Backend {
}
async fn completion(&self, params: CompletionParams) -> RpcResult<Option<CompletionResponse>> {
// We want to get the position we are in.
// Because if we are in a comment, we don't want to show completions.
let filename = params.text_document_position.text_document.uri.to_string();
if let Some(current_code) = self.current_code_map.get(&filename) {
let pos = position_to_char_index(params.text_document_position.position, &current_code);
// Let's iterate over the AST and find the node that contains the cursor.
if let Some(ast) = self.ast_map.get(&filename) {
if ast.get_non_code_meta_for_position(pos).is_some() {
// We are in a comment, don't show completions.
return Ok(None);
}
}
}
let mut completions = vec![CompletionItem {
label: PIPE_OPERATOR.to_string(),
label_details: None,