From b91edc17516d4c2a4bc93509256883a08028bacf Mon Sep 17 00:00:00 2001 From: Gabriela Araujo Britto Date: Tue, 15 Jul 2025 15:14:07 -0700 Subject: [PATCH 1/7] WIP: fix private identifiers in completions --- .../tests/completionFilterText1_test.go | 147 ++++++++++++++++++ internal/ls/completions.go | 80 +++++----- internal/scanner/scanner.go | 7 +- .../FindReferencesAfterEdit.baseline.jsonc | 36 +++++ .../conformance/privateNameHashCharName.js | 4 +- .../privateNameHashCharName.js.diff | 5 +- .../privateNameHashCharName.symbols | 2 + .../privateNameHashCharName.symbols.diff | 2 + .../conformance/privateNameHashCharName.types | 4 +- .../privateNameHashCharName.types.diff | 18 --- 10 files changed, 233 insertions(+), 72 deletions(-) create mode 100644 internal/fourslash/tests/completionFilterText1_test.go create mode 100644 testdata/baselines/reference/fourslash/findAllRef/FindReferencesAfterEdit.baseline.jsonc delete mode 100644 testdata/baselines/reference/submodule/conformance/privateNameHashCharName.types.diff diff --git a/internal/fourslash/tests/completionFilterText1_test.go b/internal/fourslash/tests/completionFilterText1_test.go new file mode 100644 index 0000000000..80667888c7 --- /dev/null +++ b/internal/fourslash/tests/completionFilterText1_test.go @@ -0,0 +1,147 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionFilterText1(t *testing.T) { + t.Parallel() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` +class Foo1 { + #bar: number; + constructor(bar: number) { + this.[|b|]/*1*/ + } +} + +class Foo5 { + #bar: number; + constructor(bar: number) { + this./*5*/ + } +} + +class Foo2 { + #bar: number; + constructor(bar: number) { + this.[|#b|]/*2*/ + } +} + +class Foo6 { + #bar: number; + constructor(bar: number) { + this.[|#|]/*6*/ + } +} + +class Foo3 { + #bar: number; + constructor(bar: number) { + b/*3*/ + } +} + +class Foo4 { + #bar: number; + constructor(bar: number) { + #b/*4*/ + } +} + +class Foo7 { + #bar: number; + constructor(bar: number) { + /*7*/ + } +} + +class Foo8 { + #bar: number; + constructor(bar: number) { + #/*8*/ + } +} +` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + // f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{ + // IsIncomplete: false, + // ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + // CommitCharacters: &defaultCommitCharacters, + // EditRange: &fourslash.EditRange{ + // Insert: f.Ranges()[0], + // Replace: f.Ranges()[0], + // }, + // }, + // Items: &fourslash.CompletionsExpectedItems{ + // Includes: []fourslash.CompletionsExpectedItem{ + // &lsproto.CompletionItem{ + // Label: "#bar", + // Kind: ptrTo(lsproto.CompletionItemKindField), + // SortText: ptrTo(string(ls.SortTextLocationPriority)), + // FilterText: ptrTo("bar"), + // }, + // }, + // }, + // }) + // f.VerifyCompletions(t, "5", &fourslash.CompletionsExpectedList{ + // IsIncomplete: false, + // ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + // CommitCharacters: &defaultCommitCharacters, + // }, + // Items: &fourslash.CompletionsExpectedItems{ + // Includes: []fourslash.CompletionsExpectedItem{ + // &lsproto.CompletionItem{ + // Label: "#bar", + // Kind: ptrTo(lsproto.CompletionItemKindField), + // SortText: ptrTo(string(ls.SortTextLocationPriority)), + // FilterText: ptrTo("bar"), + // }, + // }, + // }, + // }) + // f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + // IsIncomplete: false, + // ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + // CommitCharacters: &defaultCommitCharacters, + // EditRange: &fourslash.EditRange{ + // Insert: f.Ranges()[1], + // Replace: f.Ranges()[1], + // }, + // }, + // Items: &fourslash.CompletionsExpectedItems{ + // Includes: []fourslash.CompletionsExpectedItem{ + // &lsproto.CompletionItem{ + // Label: "#bar", + // Kind: ptrTo(lsproto.CompletionItemKindField), + // SortText: ptrTo(string(ls.SortTextLocationPriority)), + // }, + // }, + // }, + // }) + f.VerifyCompletions(t, "6", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: &fourslash.EditRange{ + Insert: f.Ranges()[2], + Replace: f.Ranges()[2], + }, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "#bar", + Kind: ptrTo(lsproto.CompletionItemKindField), + SortText: ptrTo(string(ls.SortTextLocationPriority)), + }, + }, + }, + }) +} diff --git a/internal/ls/completions.go b/internal/ls/completions.go index 670b10c444..d30750fa40 100644 --- a/internal/ls/completions.go +++ b/internal/ls/completions.go @@ -1067,7 +1067,7 @@ func getCompletionData(program *compiler.Program, typeChecker *checker.Checker, existing.Add(element.PropertyNameOrName().Text()) } uniques := core.Filter(exports, func(symbol *ast.Symbol) bool { - return symbol.Name != ast.InternalSymbolNameDefault && !existing.Has(symbol.Name) + return ast.SymbolName(symbol) != ast.InternalSymbolNameDefault && !existing.Has(ast.SymbolName(symbol)) }) symbols = append(symbols, uniques...) @@ -1103,7 +1103,7 @@ func getCompletionData(program *compiler.Program, typeChecker *checker.Checker, uniques := core.Filter( typeChecker.GetApparentProperties(typeChecker.GetTypeAtLocation(importAttributes)), func(symbol *ast.Symbol) bool { - return !existing.Has(symbol.Name) + return !existing.Has(ast.SymbolName(symbol)) }) symbols = append(symbols, uniques...) return globalsSearchSuccess @@ -1278,7 +1278,7 @@ func getCompletionData(program *compiler.Program, typeChecker *checker.Checker, // Set sort texts. for _, symbol := range filteredSymbols { symbolId := ast.GetSymbolId(symbol) - if spreadMemberNames.Has(symbol.Name) { + if spreadMemberNames.Has(ast.SymbolName(symbol)) { symbolToSortTextMap[symbolId] = SortTextMemberDeclaredBySpreadAssignment } if symbol.Flags&ast.SymbolFlagsOptional != 0 { @@ -1374,7 +1374,7 @@ func getCompletionData(program *compiler.Program, typeChecker *checker.Checker, } } - // Need to insert 'this.' before properties of `this` type, so only do that if `includeInsertTextCompletions` + // Need to insert 'this.' before properties of `this` type. if scopeNode.Kind != ast.KindSourceFile { thisType := typeChecker.TryGetThisTypeAtEx( scopeNode, @@ -1809,7 +1809,7 @@ func (l *LanguageService) createCompletionItem( } else { insertText = fmt.Sprintf( "this%s%s", - core.IfElse(insertQuestionDot, "?.", ""), + core.IfElse(insertQuestionDot, "?.", "."), name) } } else if data.propertyAccessToConvert != nil && (useBraces || insertQuestionDot) { @@ -2051,9 +2051,9 @@ func isRecommendedCompletionMatch(localSymbol *ast.Symbol, recommendedCompletion localSymbol.Flags&ast.SymbolFlagsExportValue != 0 && typeChecker.GetExportSymbolOfSymbol(localSymbol) == recommendedCompletion } -// Ported from vscode's `USUAL_WORD_SEPARATORS`. +// Ported from vscode. var wordSeparators = collections.NewSetFromItems( - '`', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '=', '+', '[', '{', ']', '}', '\\', '|', + '`', '~', '!', '@', '%', '^', '&', '*', '(', ')', '-', '=', '+', '[', '{', ']', '}', '\\', '|', ';', ':', '\'', '"', ',', '.', '<', '>', '/', '?', ) @@ -2093,21 +2093,26 @@ func getFilterText( isSnippet bool, wordStart rune, ) string { - // Private field completion. + // Private field completion, e.g. label `#bar`. if strings.HasPrefix(label, "#") { - // !!! document theses cases if insertText != "" { if strings.HasPrefix(insertText, "this.#") { if wordStart == '#' { + // `method() { this.#| }` return insertText } else { + // `method() { this.| }` + // `method() { | }` return strings.TrimPrefix(insertText, "this.#") } } } else { if wordStart == '#' { + // `method() { this.#| }` return "" } else { + // `method() { this.| }` + // `method() { | }` return strings.TrimPrefix(label, "#") } } @@ -2333,7 +2338,7 @@ func getCompletionEntryDisplayNameForSymbol( if originIncludesSymbolName(origin) { name = origin.symbolName() } else { - name = symbol.Name + name = ast.SymbolName(symbol) } if name == "" || // If the symbol is external module, don't show it in the completion list @@ -2427,7 +2432,7 @@ func originIsPromise(origin *symbolOriginInfo) bool { func getSourceFromOrigin(origin *symbolOriginInfo) string { if originIsExport(origin) { - return stringutil.StripQuotes(origin.asExport().moduleSymbol.Name) + return stringutil.StripQuotes(ast.SymbolName(origin.asExport().moduleSymbol)) } if originIsResolvedExport(origin) { @@ -3193,7 +3198,7 @@ func getJSCompletionEntries( func (l *LanguageService) getOptionalReplacementSpan(location *ast.Node, file *ast.SourceFile) *lsproto.Range { // StringLiteralLike locations are handled separately in stringCompletions.ts - if location != nil && location.Kind == ast.KindIdentifier { + if location != nil && (location.Kind == ast.KindIdentifier || location.Kind == ast.KindPrivateIdentifier) { start := astnav.GetStartOfNode(location, file, false /*includeJSDoc*/) return l.createLspRangeFromBounds(start, location.End(), file) } @@ -3840,7 +3845,7 @@ func filterClassMembersList( } return core.Filter(baseSymbols, func(propertySymbol *ast.Symbol) bool { - return !existingMemberNames.Has(propertySymbol.Name) && + return !existingMemberNames.Has(ast.SymbolName(propertySymbol)) && len(propertySymbol.Declarations) > 0 && checker.GetDeclarationModifierFlagsFromSymbol(propertySymbol)&ast.ModifierFlagsPrivate == 0 && !(propertySymbol.ValueDeclaration != nil && ast.IsPrivateIdentifierClassElementDeclaration(propertySymbol.ValueDeclaration)) @@ -4133,41 +4138,26 @@ func (l *LanguageService) createLSPCompletionItem( // Filter text // Ported from vscode ts extension. - wordRange, wordStart := getWordRange(file, position) + _, wordStart := getWordRange(file, position) if filterText == "" { filterText = getFilterText(file, position, insertText, name, isMemberCompletion, isSnippet, wordStart) } - if isMemberCompletion && !isSnippet { - accessorRange, accessorText := getDotAccessorContext(file, position) - if accessorText != "" { - filterText = accessorText + core.IfElse(insertText != "", insertText, name) - if textEdit == nil { - insertText = filterText - if wordRange != nil && clientSupportsItemInsertReplace(clientOptions) { - textEdit = &lsproto.TextEditOrInsertReplaceEdit{ - InsertReplaceEdit: &lsproto.InsertReplaceEdit{ - NewText: insertText, - Insert: *l.createLspRangeFromBounds( - accessorRange.Pos(), - accessorRange.End(), - file), - Replace: *l.createLspRangeFromBounds( - min(accessorRange.Pos(), wordRange.Pos()), - accessorRange.End(), - file), - }, - } - } else { - textEdit = &lsproto.TextEditOrInsertReplaceEdit{ - TextEdit: &lsproto.TextEdit{ - NewText: insertText, - Range: *l.createLspRangeFromBounds(accessorRange.Pos(), accessorRange.End(), file), - }, - } - } - } - } - } + // !!! TODO: remove? + // if isMemberCompletion && !isSnippet { + // accessorRange, accessorText := getDotAccessorContext(file, position) + // if accessorText != "" { + // filterText = accessorText + core.IfElse(insertText != "", insertText, name) + // if textEdit == nil { + // insertText = filterText + // textEdit = &lsproto.TextEditOrInsertReplaceEdit{ + // TextEdit: &lsproto.TextEdit{ + // NewText: insertText, + // Range: *l.createLspRangeFromBounds(accessorRange.Pos(), accessorRange.End(), file), + // }, + // } + // } + // } + // } // Adjustements based on kind modifiers. var tags *[]lsproto.CompletionItemTag diff --git a/internal/scanner/scanner.go b/internal/scanner/scanner.go index 41450e1b5a..7a44b1fcde 100644 --- a/internal/scanner/scanner.go +++ b/internal/scanner/scanner.go @@ -863,12 +863,11 @@ func (s *Scanner) Scan() ast.Kind { } s.pos-- } - if s.scanIdentifier(1) { - s.token = ast.KindPrivateIdentifier - } else { + if !s.scanIdentifier(1) { s.errorAt(diagnostics.Invalid_character, s.pos-1, 1) - s.token = ast.KindUnknown + s.tokenValue = "#" } + s.token = ast.KindPrivateIdentifier default: if ch < 0 { s.token = ast.KindEndOfFile diff --git a/testdata/baselines/reference/fourslash/findAllRef/FindReferencesAfterEdit.baseline.jsonc b/testdata/baselines/reference/fourslash/findAllRef/FindReferencesAfterEdit.baseline.jsonc new file mode 100644 index 0000000000..9123c0f239 --- /dev/null +++ b/testdata/baselines/reference/fourslash/findAllRef/FindReferencesAfterEdit.baseline.jsonc @@ -0,0 +1,36 @@ +// === findAllReferences === +// === /a.ts === + +// interface A { +// /*FIND ALL REFS*/[|foo|]: string; +// } + + +// === /b.ts === + +// /// +// +// +// function foo(x: A) { +// x.[|foo|] +// } + + + + +// === findAllReferences === +// === /a.ts === + +// interface A { +// [|foo|]: string; +// } + + +// === /b.ts === + +// /// +// +// +// function foo(x: A) { +// x./*FIND ALL REFS*/[|foo|] +// } diff --git a/testdata/baselines/reference/submodule/conformance/privateNameHashCharName.js b/testdata/baselines/reference/submodule/conformance/privateNameHashCharName.js index e416b5fe85..e0d789d956 100644 --- a/testdata/baselines/reference/submodule/conformance/privateNameHashCharName.js +++ b/testdata/baselines/reference/submodule/conformance/privateNameHashCharName.js @@ -13,8 +13,10 @@ class C { //// [privateNameHashCharName.js] +#; class C { + #; m() { - this.; + this.#; } } diff --git a/testdata/baselines/reference/submodule/conformance/privateNameHashCharName.js.diff b/testdata/baselines/reference/submodule/conformance/privateNameHashCharName.js.diff index 2b68913042..ce0a642a2e 100644 --- a/testdata/baselines/reference/submodule/conformance/privateNameHashCharName.js.diff +++ b/testdata/baselines/reference/submodule/conformance/privateNameHashCharName.js.diff @@ -10,14 +10,15 @@ - return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); -}; -var _C_; --#; + #; class C { - constructor() { - _C_.set(this, void 0); - } ++ #; m() { - __classPrivateFieldGet(this, _C_, "f"); -+ this.; ++ this.#; } } -_C_ = new WeakMap(); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/privateNameHashCharName.symbols b/testdata/baselines/reference/submodule/conformance/privateNameHashCharName.symbols index 94a17f9076..4e5ec9c76a 100644 --- a/testdata/baselines/reference/submodule/conformance/privateNameHashCharName.symbols +++ b/testdata/baselines/reference/submodule/conformance/privateNameHashCharName.symbols @@ -7,11 +7,13 @@ class C { >C : Symbol(C, Decl(privateNameHashCharName.ts, 0, 1)) # +># : Symbol(#, Decl(privateNameHashCharName.ts, 2, 9)) m() { >m : Symbol(m, Decl(privateNameHashCharName.ts, 3, 5)) this.# +>this.# : Symbol(#, Decl(privateNameHashCharName.ts, 2, 9)) >this : Symbol(C, Decl(privateNameHashCharName.ts, 0, 1)) } } diff --git a/testdata/baselines/reference/submodule/conformance/privateNameHashCharName.symbols.diff b/testdata/baselines/reference/submodule/conformance/privateNameHashCharName.symbols.diff index d8dce96b95..ee5e06935b 100644 --- a/testdata/baselines/reference/submodule/conformance/privateNameHashCharName.symbols.diff +++ b/testdata/baselines/reference/submodule/conformance/privateNameHashCharName.symbols.diff @@ -5,6 +5,7 @@ # -># : Symbol(C[#], Decl(privateNameHashCharName.ts, 2, 9)) ++># : Symbol(#, Decl(privateNameHashCharName.ts, 2, 9)) m() { ->m : Symbol(C.m, Decl(privateNameHashCharName.ts, 3, 5)) @@ -12,6 +13,7 @@ this.# ->this.# : Symbol(C[#], Decl(privateNameHashCharName.ts, 2, 9)) ++>this.# : Symbol(#, Decl(privateNameHashCharName.ts, 2, 9)) >this : Symbol(C, Decl(privateNameHashCharName.ts, 0, 1)) } } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/privateNameHashCharName.types b/testdata/baselines/reference/submodule/conformance/privateNameHashCharName.types index d93dc1ca7c..10ba495a5e 100644 --- a/testdata/baselines/reference/submodule/conformance/privateNameHashCharName.types +++ b/testdata/baselines/reference/submodule/conformance/privateNameHashCharName.types @@ -7,14 +7,14 @@ class C { >C : C # +># : any m() { >m : () => void this.# ->this. : any +>this.# : any >this : this -> : any } } diff --git a/testdata/baselines/reference/submodule/conformance/privateNameHashCharName.types.diff b/testdata/baselines/reference/submodule/conformance/privateNameHashCharName.types.diff deleted file mode 100644 index 510e0f1843..0000000000 --- a/testdata/baselines/reference/submodule/conformance/privateNameHashCharName.types.diff +++ /dev/null @@ -1,18 +0,0 @@ ---- old.privateNameHashCharName.types -+++ new.privateNameHashCharName.types -@@= skipped -6, +6 lines =@@ - >C : C - - # --># : any - - m() { - >m : () => void - - this.# -->this.# : any -+>this. : any - >this : this -+> : any - } - } From 790adfb0953a2fafb48bb9b05e68af71af7e19dc Mon Sep 17 00:00:00 2001 From: Gabriela Araujo Britto Date: Wed, 16 Jul 2025 10:28:52 -0700 Subject: [PATCH 2/7] finish private id tests and simplification --- .../tests/completionFilterText1_test.go | 206 ++++++++++++------ internal/ls/completions.go | 5 +- 2 files changed, 145 insertions(+), 66 deletions(-) diff --git a/internal/fourslash/tests/completionFilterText1_test.go b/internal/fourslash/tests/completionFilterText1_test.go index 80667888c7..a24d931330 100644 --- a/internal/fourslash/tests/completionFilterText1_test.go +++ b/internal/fourslash/tests/completionFilterText1_test.go @@ -44,87 +44,87 @@ class Foo6 { class Foo3 { #bar: number; constructor(bar: number) { - b/*3*/ + [|b|]/*3*/ } } -class Foo4 { - #bar: number; - constructor(bar: number) { - #b/*4*/ - } +class Foo7 { + #bar: number; + constructor(bar: number) { + /*7*/ + } } -class Foo7 { +class Foo4 { #bar: number; constructor(bar: number) { - /*7*/ + [|#b|]/*4*/ } } class Foo8 { #bar: number; constructor(bar: number) { - #/*8*/ + [|#|]/*8*/ } } ` f := fourslash.NewFourslash(t, nil /*capabilities*/, content) - // f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{ - // IsIncomplete: false, - // ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ - // CommitCharacters: &defaultCommitCharacters, - // EditRange: &fourslash.EditRange{ - // Insert: f.Ranges()[0], - // Replace: f.Ranges()[0], - // }, - // }, - // Items: &fourslash.CompletionsExpectedItems{ - // Includes: []fourslash.CompletionsExpectedItem{ - // &lsproto.CompletionItem{ - // Label: "#bar", - // Kind: ptrTo(lsproto.CompletionItemKindField), - // SortText: ptrTo(string(ls.SortTextLocationPriority)), - // FilterText: ptrTo("bar"), - // }, - // }, - // }, - // }) - // f.VerifyCompletions(t, "5", &fourslash.CompletionsExpectedList{ - // IsIncomplete: false, - // ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ - // CommitCharacters: &defaultCommitCharacters, - // }, - // Items: &fourslash.CompletionsExpectedItems{ - // Includes: []fourslash.CompletionsExpectedItem{ - // &lsproto.CompletionItem{ - // Label: "#bar", - // Kind: ptrTo(lsproto.CompletionItemKindField), - // SortText: ptrTo(string(ls.SortTextLocationPriority)), - // FilterText: ptrTo("bar"), - // }, - // }, - // }, - // }) - // f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ - // IsIncomplete: false, - // ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ - // CommitCharacters: &defaultCommitCharacters, - // EditRange: &fourslash.EditRange{ - // Insert: f.Ranges()[1], - // Replace: f.Ranges()[1], - // }, - // }, - // Items: &fourslash.CompletionsExpectedItems{ - // Includes: []fourslash.CompletionsExpectedItem{ - // &lsproto.CompletionItem{ - // Label: "#bar", - // Kind: ptrTo(lsproto.CompletionItemKindField), - // SortText: ptrTo(string(ls.SortTextLocationPriority)), - // }, - // }, - // }, - // }) + f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: &fourslash.EditRange{ + Insert: f.Ranges()[0], + Replace: f.Ranges()[0], + }, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "#bar", + Kind: ptrTo(lsproto.CompletionItemKindField), + SortText: ptrTo(string(ls.SortTextLocationPriority)), + FilterText: ptrTo("bar"), + }, + }, + }, + }) + f.VerifyCompletions(t, "5", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "#bar", + Kind: ptrTo(lsproto.CompletionItemKindField), + SortText: ptrTo(string(ls.SortTextLocationPriority)), + FilterText: ptrTo("bar"), + }, + }, + }, + }) + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: &fourslash.EditRange{ + Insert: f.Ranges()[1], + Replace: f.Ranges()[1], + }, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "#bar", + Kind: ptrTo(lsproto.CompletionItemKindField), + SortText: ptrTo(string(ls.SortTextLocationPriority)), + }, + }, + }, + }) f.VerifyCompletions(t, "6", &fourslash.CompletionsExpectedList{ IsIncomplete: false, ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ @@ -144,4 +144,82 @@ class Foo8 { }, }, }) + f.VerifyCompletions(t, "3", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: &fourslash.EditRange{ + Insert: f.Ranges()[3], + Replace: f.Ranges()[3], + }, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "#bar", + Kind: ptrTo(lsproto.CompletionItemKindField), + SortText: ptrTo(string(ls.SortTextSuggestedClassMembers)), + FilterText: ptrTo("bar"), + InsertText: ptrTo("this.#bar"), + }, + }, + }, + }) + f.VerifyCompletions(t, "7", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "#bar", + Kind: ptrTo(lsproto.CompletionItemKindField), + SortText: ptrTo(string(ls.SortTextSuggestedClassMembers)), + FilterText: ptrTo("bar"), + InsertText: ptrTo("this.#bar"), + }, + }, + }, + }) + f.VerifyCompletions(t, "4", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: &fourslash.EditRange{ + Insert: f.Ranges()[4], + Replace: f.Ranges()[4], + }, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "#bar", + Kind: ptrTo(lsproto.CompletionItemKindField), + SortText: ptrTo(string(ls.SortTextSuggestedClassMembers)), + InsertText: ptrTo("this.#bar"), + }, + }, + }, + }) + f.VerifyCompletions(t, "8", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: &fourslash.EditRange{ + Insert: f.Ranges()[5], + Replace: f.Ranges()[5], + }, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "#bar", + Kind: ptrTo(lsproto.CompletionItemKindField), + SortText: ptrTo(string(ls.SortTextSuggestedClassMembers)), + InsertText: ptrTo("this.#bar"), + }, + }, + }, + }) } diff --git a/internal/ls/completions.go b/internal/ls/completions.go index d30750fa40..4d8c99d477 100644 --- a/internal/ls/completions.go +++ b/internal/ls/completions.go @@ -2099,7 +2099,8 @@ func getFilterText( if strings.HasPrefix(insertText, "this.#") { if wordStart == '#' { // `method() { this.#| }` - return insertText + // `method() { #| }` + return "" } else { // `method() { this.| }` // `method() { | }` @@ -2118,7 +2119,7 @@ func getFilterText( } } - // For `this.` completions, generally don't set the filter text since we don't want them to be overly prioritized. microsoft/vscode#74164 + // For `this.` completions, generally don't set the filter text since we don't want them to be overly deprioritized. microsoft/vscode#74164 if strings.HasPrefix(insertText, "this.") { return "" } From 647399aa05f2c6d409a64adffdd549dc5bea78fe Mon Sep 17 00:00:00 2001 From: Gabriela Araujo Britto Date: Thu, 17 Jul 2025 12:02:16 -0700 Subject: [PATCH 3/7] more tests for filter text + parser fix --- .../tests/completionFilterText2_test.go | 63 +++++++++ .../tests/completionFilterText3_test.go | 126 ++++++++++++++++++ internal/ls/completions.go | 28 +++- internal/parser/parser.go | 3 +- 4 files changed, 216 insertions(+), 4 deletions(-) create mode 100644 internal/fourslash/tests/completionFilterText2_test.go create mode 100644 internal/fourslash/tests/completionFilterText3_test.go diff --git a/internal/fourslash/tests/completionFilterText2_test.go b/internal/fourslash/tests/completionFilterText2_test.go new file mode 100644 index 0000000000..4cfd822cb3 --- /dev/null +++ b/internal/fourslash/tests/completionFilterText2_test.go @@ -0,0 +1,63 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionFilterText2(t *testing.T) { + t.Parallel() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @strict: true +declare const foo1: { bar: string } | undefined; +if (true) { + foo1[|.|]/*1*/ +} +else { + foo1?./*2*/ +} +` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "bar", + Kind: ptrTo(lsproto.CompletionItemKindField), + SortText: ptrTo(string(ls.SortTextLocationPriority)), + InsertText: ptrTo("?.bar"), + FilterText: ptrTo("?.bar"), + TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ + TextEdit: &lsproto.TextEdit{ + NewText: "?.bar", + Range: f.Ranges()[0].LSRange, + }, + }, + }, + }, + }, + }) + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "bar", + Kind: ptrTo(lsproto.CompletionItemKindField), + SortText: ptrTo(string(ls.SortTextLocationPriority)), + }, + }, + }, + }) +} diff --git a/internal/fourslash/tests/completionFilterText3_test.go b/internal/fourslash/tests/completionFilterText3_test.go new file mode 100644 index 0000000000..41e01f64d1 --- /dev/null +++ b/internal/fourslash/tests/completionFilterText3_test.go @@ -0,0 +1,126 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionFilterText3(t *testing.T) { + t.Parallel() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @strict: true +declare const foo1: { b: number; "a bc": string; }; +if (true) { + foo1[|.|]/*1*/ +} +else { + foo1[|.a|]/*2*/ +} + +declare const foo2: { b: number; "a bc": string; } | undefined; +if (true) { + foo2[|.|]/*3*/ +} else { + foo2[|.a|]/*4*/ +} +` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "a bc", + Kind: ptrTo(lsproto.CompletionItemKindField), + SortText: ptrTo(string(ls.SortTextLocationPriority)), + InsertText: ptrTo("[\"a bc\"]"), + FilterText: ptrTo(".a bc"), + TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ + TextEdit: &lsproto.TextEdit{ + NewText: "[\"a bc\"]", + Range: f.Ranges()[0].LSRange, + }, + }, + }, + }, + }, + }) + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "a bc", + Kind: ptrTo(lsproto.CompletionItemKindField), + SortText: ptrTo(string(ls.SortTextLocationPriority)), + InsertText: ptrTo("[\"a bc\"]"), + FilterText: ptrTo(".a bc"), + TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ + TextEdit: &lsproto.TextEdit{ + NewText: "[\"a bc\"]", + Range: f.Ranges()[1].LSRange, + }, + }, + }, + }, + }, + }) + f.VerifyCompletions(t, "3", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "a bc", + Kind: ptrTo(lsproto.CompletionItemKindField), + SortText: ptrTo(string(ls.SortTextLocationPriority)), + InsertText: ptrTo("?.[\"a bc\"]"), + FilterText: ptrTo(".a bc"), + TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ + TextEdit: &lsproto.TextEdit{ + NewText: "?.[\"a bc\"]", + Range: f.Ranges()[2].LSRange, + }, + }, + }, + }, + }, + }) + f.VerifyCompletions(t, "4", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "a bc", + Kind: ptrTo(lsproto.CompletionItemKindField), + SortText: ptrTo(string(ls.SortTextLocationPriority)), + InsertText: ptrTo("?.[\"a bc\"]"), + FilterText: ptrTo(".a bc"), + TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ + TextEdit: &lsproto.TextEdit{ + NewText: "?.[\"a bc\"]", + Range: f.Ranges()[3].LSRange, + }, + }, + }, + }, + }, + }) +} diff --git a/internal/ls/completions.go b/internal/ls/completions.go index 4d8c99d477..63efe13ae9 100644 --- a/internal/ls/completions.go +++ b/internal/ls/completions.go @@ -2089,8 +2089,6 @@ func getFilterText( position int, insertText string, label string, - isMemberCompletion bool, - isSnippet bool, wordStart rune, ) string { // Private field completion, e.g. label `#bar`. @@ -2141,6 +2139,30 @@ func getFilterText( return insertText } + if strings.HasPrefix(insertText, "?.") { + // Handle this case like the case above: + // ``` + // const xyz = { 'ab c': 1 } | undefined; + // xyz.ab| + // ``` + // filterText should be `.ab c` instead of `?.['ab c']`. + if strings.HasPrefix(insertText, "?.[") { + if strings.HasPrefix(insertText, `?.['`) && strings.HasSuffix(insertText, `']`) { + return "." + strings.TrimPrefix(strings.TrimSuffix(insertText, `']`), `?.['`) + } + if strings.HasPrefix(insertText, `?.["`) && strings.HasSuffix(insertText, `"]`) { + return "." + strings.TrimPrefix(strings.TrimSuffix(insertText, `"]`), `?.["`) + } + } else { + // ``` + // const xyz = { abc: 1 } | undefined; + // xyz.ab| + // ``` + // filterText should be `.abc` instead of `?.abc. + return strings.TrimPrefix(insertText, "?") + } + } + // In all other cases, fall back to using the insertText. return insertText } @@ -4141,7 +4163,7 @@ func (l *LanguageService) createLSPCompletionItem( // Ported from vscode ts extension. _, wordStart := getWordRange(file, position) if filterText == "" { - filterText = getFilterText(file, position, insertText, name, isMemberCompletion, isSnippet, wordStart) + filterText = getFilterText(file, position, insertText, name, wordStart) } // !!! TODO: remove? // if isMemberCompletion && !isSnippet { diff --git a/internal/parser/parser.go b/internal/parser/parser.go index 6cc354802a..cd39d643ae 100644 --- a/internal/parser/parser.go +++ b/internal/parser/parser.go @@ -5473,7 +5473,8 @@ func (p *Parser) parseCallExpressionRest(pos int, expression *ast.Expression) *a if questionDotToken != nil { // We parsed `?.` but then failed to parse anything, so report a missing identifier here. p.parseErrorAtCurrentToken(diagnostics.Identifier_expected) - expression = p.createMissingIdentifier() + name := p.createMissingIdentifier() + expression = p.factory.NewPropertyAccessExpression(expression, questionDotToken, name, ast.NodeFlagsOptionalChain) p.finishNode(expression, pos) } break From 0fcdff03ac91550be8e69a8add97031fea41e526 Mon Sep 17 00:00:00 2001 From: Gabriela Araujo Britto Date: Thu, 17 Jul 2025 14:48:24 -0700 Subject: [PATCH 4/7] fix tests, refactor completion filter text --- internal/fourslash/tests/basicEdit_test.go | 17 +- .../tests/basicInterfaceMembers_test.go | 17 +- .../tests/basicMultifileCompletions_test.go | 17 +- .../tests/completionFilterText2_test.go | 2 +- .../tests/completionFilterText3_test.go | 29 +- .../tests/completionFilterText4_test.go | 42 ++ internal/ls/completions.go | 79 ++- internal/ls/completions_test.go | 455 +++--------------- 8 files changed, 165 insertions(+), 493 deletions(-) create mode 100644 internal/fourslash/tests/completionFilterText4_test.go diff --git a/internal/fourslash/tests/basicEdit_test.go b/internal/fourslash/tests/basicEdit_test.go index bbd07cc72b..5341806651 100644 --- a/internal/fourslash/tests/basicEdit_test.go +++ b/internal/fourslash/tests/basicEdit_test.go @@ -31,20 +31,9 @@ p/*a*/` Items: &fourslash.CompletionsExpectedItems{ Exact: []fourslash.CompletionsExpectedItem{ &lsproto.CompletionItem{ - Label: "x", - Kind: ptrTo(lsproto.CompletionItemKindField), - SortText: ptrTo(string(ls.SortTextLocationPriority)), - InsertText: ptrTo(".x"), - FilterText: ptrTo(".x"), - TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ - TextEdit: &lsproto.TextEdit{ - NewText: ".x", - Range: lsproto.Range{ - Start: lsproto.Position{Line: 6, Character: 1}, - End: lsproto.Position{Line: 6, Character: 2}, - }, - }, - }, + Label: "x", + Kind: ptrTo(lsproto.CompletionItemKindField), + SortText: ptrTo(string(ls.SortTextLocationPriority)), }, "y", }, diff --git a/internal/fourslash/tests/basicInterfaceMembers_test.go b/internal/fourslash/tests/basicInterfaceMembers_test.go index 0564cea3ba..7a34271a58 100644 --- a/internal/fourslash/tests/basicInterfaceMembers_test.go +++ b/internal/fourslash/tests/basicInterfaceMembers_test.go @@ -28,20 +28,9 @@ p./*a*/` Items: &fourslash.CompletionsExpectedItems{ Exact: []fourslash.CompletionsExpectedItem{ &lsproto.CompletionItem{ - Label: "x", - Kind: ptrTo(lsproto.CompletionItemKindField), - SortText: ptrTo(string(ls.SortTextLocationPriority)), - InsertText: ptrTo(".x"), - FilterText: ptrTo(".x"), - TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ - TextEdit: &lsproto.TextEdit{ - NewText: ".x", - Range: lsproto.Range{ - Start: lsproto.Position{Line: 6, Character: 1}, - End: lsproto.Position{Line: 6, Character: 2}, - }, - }, - }, + Label: "x", + Kind: ptrTo(lsproto.CompletionItemKindField), + SortText: ptrTo(string(ls.SortTextLocationPriority)), }, "y", }, diff --git a/internal/fourslash/tests/basicMultifileCompletions_test.go b/internal/fourslash/tests/basicMultifileCompletions_test.go index 5dbe310b06..9171cbd3ba 100644 --- a/internal/fourslash/tests/basicMultifileCompletions_test.go +++ b/internal/fourslash/tests/basicMultifileCompletions_test.go @@ -27,20 +27,9 @@ const test = foo./*1*/` Items: &fourslash.CompletionsExpectedItems{ Includes: []fourslash.CompletionsExpectedItem{ &lsproto.CompletionItem{ - Label: "bar", - Kind: ptrTo(lsproto.CompletionItemKindField), - SortText: ptrTo(string(ls.SortTextLocationPriority)), - FilterText: ptrTo(".bar"), - InsertText: ptrTo(".bar"), - TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ - TextEdit: &lsproto.TextEdit{ - NewText: ".bar", - Range: lsproto.Range{ - Start: lsproto.Position{Line: 1, Character: 16}, - End: lsproto.Position{Line: 1, Character: 17}, - }, - }, - }, + Label: "bar", + Kind: ptrTo(lsproto.CompletionItemKindField), + SortText: ptrTo(string(ls.SortTextLocationPriority)), }, }, }, diff --git a/internal/fourslash/tests/completionFilterText2_test.go b/internal/fourslash/tests/completionFilterText2_test.go index 4cfd822cb3..472b71ad6a 100644 --- a/internal/fourslash/tests/completionFilterText2_test.go +++ b/internal/fourslash/tests/completionFilterText2_test.go @@ -34,7 +34,7 @@ else { Kind: ptrTo(lsproto.CompletionItemKindField), SortText: ptrTo(string(ls.SortTextLocationPriority)), InsertText: ptrTo("?.bar"), - FilterText: ptrTo("?.bar"), + FilterText: ptrTo(".bar"), TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ TextEdit: &lsproto.TextEdit{ NewText: "?.bar", diff --git a/internal/fourslash/tests/completionFilterText3_test.go b/internal/fourslash/tests/completionFilterText3_test.go index 41e01f64d1..71cad8c60e 100644 --- a/internal/fourslash/tests/completionFilterText3_test.go +++ b/internal/fourslash/tests/completionFilterText3_test.go @@ -16,7 +16,7 @@ func TestCompletionFilterText3(t *testing.T) { declare const foo1: { b: number; "a bc": string; }; if (true) { foo1[|.|]/*1*/ -} +} else { foo1[|.a|]/*2*/ } @@ -24,8 +24,10 @@ else { declare const foo2: { b: number; "a bc": string; } | undefined; if (true) { foo2[|.|]/*3*/ -} else { +} else if (false) { foo2[|.a|]/*4*/ +} else { + foo2[|?.|]/*5*/ } ` f := fourslash.NewFourslash(t, nil /*capabilities*/, content) @@ -123,4 +125,27 @@ if (true) { }, }, }) + f.VerifyCompletions(t, "5", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "a bc", + Kind: ptrTo(lsproto.CompletionItemKindField), + SortText: ptrTo(string(ls.SortTextLocationPriority)), + InsertText: ptrTo("?.[\"a bc\"]"), + FilterText: ptrTo("?.a bc"), + TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ + TextEdit: &lsproto.TextEdit{ + NewText: "?.[\"a bc\"]", + Range: f.Ranges()[4].LSRange, + }, + }, + }, + }, + }, + }) } diff --git a/internal/fourslash/tests/completionFilterText4_test.go b/internal/fourslash/tests/completionFilterText4_test.go new file mode 100644 index 0000000000..92ebec8ea5 --- /dev/null +++ b/internal/fourslash/tests/completionFilterText4_test.go @@ -0,0 +1,42 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionFilterText4(t *testing.T) { + t.Parallel() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `declare const x: [number, number]; +x[|.|]/**/; +` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "0", + Kind: ptrTo(lsproto.CompletionItemKindField), + SortText: ptrTo(string(ls.SortTextLocationPriority)), + InsertText: ptrTo("[0]"), + FilterText: ptrTo(".0"), + TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ + TextEdit: &lsproto.TextEdit{ + NewText: "[0]", + Range: f.Ranges()[0].LSRange, + }, + }, + }, + }, + }, + }) +} diff --git a/internal/ls/completions.go b/internal/ls/completions.go index 63efe13ae9..6d3f5a5be7 100644 --- a/internal/ls/completions.go +++ b/internal/ls/completions.go @@ -2059,7 +2059,7 @@ var wordSeparators = collections.NewSetFromItems( // Finds the range of the word that ends at the given position. // e.g. for "abc def.ghi|jkl", the word range is "ghi" and the word start is 'g'. -func getWordRange(sourceFile *ast.SourceFile, position int) (wordRange *core.TextRange, wordStart rune) { +func getWordRange(sourceFile *ast.SourceFile, position int) (wordSize int, wordStart rune) { // !!! Port other case of vscode's `DEFAULT_WORD_REGEXP` that covers words that start like numbers, e.g. -123.456abcd. text := sourceFile.Text()[:position] totalSize := 0 @@ -2076,11 +2076,22 @@ func getWordRange(sourceFile *ast.SourceFile, position int) (wordRange *core.Tex totalSize -= 1 firstRune, _ = utf8.DecodeRuneInString(text[len(text)-totalSize:]) } - if totalSize == 0 { - return nil, firstRune + return totalSize, firstRune +} + +// `["ab c"]` -> `ab c` +// `['ab c']` -> `ab c` +// `[123]` -> `123` +func trimElementAccess(text string) string { + text = strings.TrimPrefix(text, "[") + text = strings.TrimSuffix(text, "]") + if strings.HasPrefix(text, `'`) && strings.HasSuffix(text, `'`) { + text = strings.TrimPrefix(strings.TrimSuffix(text, `'`), `'`) } - textRange := core.NewTextRange(position-totalSize, position) - return &textRange, firstRune + if strings.HasPrefix(text, `"`) && strings.HasSuffix(text, `"`) { + text = strings.TrimPrefix(strings.TrimSuffix(text, `"`), `"`) + } + return text } // Ported from vscode ts extension: `getFilterText`. @@ -2090,6 +2101,7 @@ func getFilterText( insertText string, label string, wordStart rune, + dotAccessor string, ) string { // Private field completion, e.g. label `#bar`. if strings.HasPrefix(label, "#") { @@ -2130,13 +2142,7 @@ func getFilterText( // In which case we want to insert a bracket accessor but should use `.abc` as the filter text instead of // the bracketed insert text. if strings.HasPrefix(insertText, "[") { - if strings.HasPrefix(insertText, `['`) && strings.HasSuffix(insertText, `']`) { - return "." + strings.TrimPrefix(strings.TrimSuffix(insertText, `']`), `['`) - } - if strings.HasPrefix(insertText, `["`) && strings.HasSuffix(insertText, `"]`) { - return "." + strings.TrimPrefix(strings.TrimSuffix(insertText, `"]`), `["`) - } - return insertText + return dotAccessor + trimElementAccess(insertText) } if strings.HasPrefix(insertText, "?.") { @@ -2147,19 +2153,14 @@ func getFilterText( // ``` // filterText should be `.ab c` instead of `?.['ab c']`. if strings.HasPrefix(insertText, "?.[") { - if strings.HasPrefix(insertText, `?.['`) && strings.HasSuffix(insertText, `']`) { - return "." + strings.TrimPrefix(strings.TrimSuffix(insertText, `']`), `?.['`) - } - if strings.HasPrefix(insertText, `?.["`) && strings.HasSuffix(insertText, `"]`) { - return "." + strings.TrimPrefix(strings.TrimSuffix(insertText, `"]`), `?.["`) - } + return dotAccessor + trimElementAccess(insertText[2:]) } else { // ``` // const xyz = { abc: 1 } | undefined; // xyz.ab| // ``` // filterText should be `.abc` instead of `?.abc. - return strings.TrimPrefix(insertText, "?") + return dotAccessor + insertText[2:] } } @@ -2168,27 +2169,18 @@ func getFilterText( } // Ported from vscode's `provideCompletionItems`. -func getDotAccessorContext(file *ast.SourceFile, position int) (acessorRange *core.TextRange, accessorText string) { +func getDotAccessor(file *ast.SourceFile, position int) string { text := file.Text()[:position] totalSize := 0 - for r, size := utf8.DecodeLastRuneInString(text); size != 0; r, size = utf8.DecodeLastRuneInString(text[:len(text)-totalSize]) { - if !unicode.IsSpace(r) { - break - } - totalSize += size - text = text[:len(text)-size] - } if strings.HasSuffix(text, "?.") { totalSize += 2 - newRange := core.NewTextRange(position-totalSize, position) - return &newRange, file.Text()[position-totalSize : position] + return file.Text()[position-totalSize : position] } if strings.HasSuffix(text, ".") { totalSize += 1 - newRange := core.NewTextRange(position-totalSize, position) - return &newRange, file.Text()[position-totalSize : position] + return file.Text()[position-totalSize : position] } - return nil, "" + return "" } func strPtrTo(v string) *string { @@ -4161,26 +4153,11 @@ func (l *LanguageService) createLSPCompletionItem( // Filter text // Ported from vscode ts extension. - _, wordStart := getWordRange(file, position) + wordSize, wordStart := getWordRange(file, position) + dotAccessor := getDotAccessor(file, position-wordSize) if filterText == "" { - filterText = getFilterText(file, position, insertText, name, wordStart) - } - // !!! TODO: remove? - // if isMemberCompletion && !isSnippet { - // accessorRange, accessorText := getDotAccessorContext(file, position) - // if accessorText != "" { - // filterText = accessorText + core.IfElse(insertText != "", insertText, name) - // if textEdit == nil { - // insertText = filterText - // textEdit = &lsproto.TextEditOrInsertReplaceEdit{ - // TextEdit: &lsproto.TextEdit{ - // NewText: insertText, - // Range: *l.createLspRangeFromBounds(accessorRange.Pos(), accessorRange.End(), file), - // }, - // } - // } - // } - // } + filterText = getFilterText(file, position, insertText, name, wordStart, dotAccessor) + } // Adjustements based on kind modifiers. var tags *[]lsproto.CompletionItemTag diff --git a/internal/ls/completions_test.go b/internal/ls/completions_test.go index 79166b1afe..e78905282d 100644 --- a/internal/ls/completions_test.go +++ b/internal/ls/completions_test.go @@ -111,117 +111,6 @@ func TestCompletions(t *testing.T) { } testCases := []testCase{ - { - name: "basicInterfaceMembers", - files: map[string]string{ - defaultMainFileName: `export {}; -interface Point { - x: number; - y: number; -} -declare const p: Point; -p./*a*/`, - }, - expectedResult: map[string]*testCaseResult{ - "a": { - list: &lsproto.CompletionList{ - IsIncomplete: false, - ItemDefaults: itemDefaults, - Items: []*lsproto.CompletionItem{ - { - Label: "x", - Kind: fieldKind, - SortText: sortTextLocationPriority, - FilterText: ptrTo(".x"), - InsertText: ptrTo(".x"), - TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ - TextEdit: &lsproto.TextEdit{ - NewText: ".x", - Range: lsproto.Range{ - Start: lsproto.Position{Line: 6, Character: 1}, - End: lsproto.Position{Line: 6, Character: 2}, - }, - }, - }, - }, - { - Label: "y", - Kind: fieldKind, - SortText: sortTextLocationPriority, - FilterText: ptrTo(".y"), - InsertText: ptrTo(".y"), - TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ - TextEdit: &lsproto.TextEdit{ - NewText: ".y", - Range: lsproto.Range{ - Start: lsproto.Position{Line: 6, Character: 1}, - End: lsproto.Position{Line: 6, Character: 2}, - }, - }, - }, - }, - }, - }, - }, - }, - }, - { - name: "basicInterfaceMembersOptional", - files: map[string]string{ - "/tsconfig.json": `{ "compilerOptions": { "strict": true } }`, - defaultMainFileName: `export {}; -interface Point { - x: number; - y: number; -} -declare const p: Point | undefined; -p./*a*/`, - }, - expectedResult: map[string]*testCaseResult{ - "a": { - list: &lsproto.CompletionList{ - IsIncomplete: false, - ItemDefaults: itemDefaults, - Items: []*lsproto.CompletionItem{ - { - Label: "x", - Kind: fieldKind, - SortText: sortTextLocationPriority, - FilterText: ptrTo(".?.x"), - InsertText: ptrTo("?.x"), - - TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ - TextEdit: &lsproto.TextEdit{ - NewText: "?.x", - Range: lsproto.Range{ - Start: lsproto.Position{Line: 6, Character: 1}, - End: lsproto.Position{Line: 6, Character: 2}, - }, - }, - }, - }, - { - Label: "y", - Kind: fieldKind, - SortText: sortTextLocationPriority, - FilterText: ptrTo(".?.y"), - InsertText: ptrTo("?.y"), - - TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ - TextEdit: &lsproto.TextEdit{ - NewText: "?.y", - Range: lsproto.Range{ - Start: lsproto.Position{Line: 6, Character: 1}, - End: lsproto.Position{Line: 6, Character: 2}, - }, - }, - }, - }, - }, - }, - }, - }, - }, { name: "objectLiteralType", files: map[string]string{ @@ -236,20 +125,9 @@ x./*a*/`, ItemDefaults: itemDefaults, Items: []*lsproto.CompletionItem{ { - Label: "foo", - Kind: fieldKind, - SortText: sortTextLocationPriority, - InsertText: ptrTo(".foo"), - FilterText: ptrTo(".foo"), - TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ - TextEdit: &lsproto.TextEdit{ - NewText: ".foo", - Range: lsproto.Range{ - Start: lsproto.Position{Line: 2, Character: 1}, - End: lsproto.Position{Line: 2, Character: 2}, - }, - }, - }, + Label: "foo", + Kind: fieldKind, + SortText: sortTextLocationPriority, }, }, }, @@ -272,36 +150,14 @@ var t = new n(0, 1, '');t./*a*/`, ItemDefaults: itemDefaults, Items: []*lsproto.CompletionItem{ { - Label: "x", - Kind: fieldKind, - SortText: sortTextLocationPriority, - FilterText: ptrTo(".x"), - InsertText: ptrTo(".x"), - TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ - TextEdit: &lsproto.TextEdit{ - NewText: ".x", - Range: lsproto.Range{ - Start: lsproto.Position{Line: 3, Character: 25}, - End: lsproto.Position{Line: 3, Character: 26}, - }, - }, - }, + Label: "x", + Kind: fieldKind, + SortText: sortTextLocationPriority, }, { - Label: "y", - Kind: fieldKind, - SortText: sortTextLocationPriority, - FilterText: ptrTo(".y"), - InsertText: ptrTo(".y"), - TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ - TextEdit: &lsproto.TextEdit{ - NewText: ".y", - Range: lsproto.Range{ - Start: lsproto.Position{Line: 3, Character: 25}, - End: lsproto.Position{Line: 3, Character: 26}, - }, - }, - }, + Label: "y", + Kind: fieldKind, + SortText: sortTextLocationPriority, }, }, }, @@ -340,196 +196,64 @@ D./*a*/`, ItemDefaults: itemDefaults, Items: []*lsproto.CompletionItem{ // !!! `funcionMembersPlus` { - Label: "bar", - Kind: methodKind, - SortText: sortTextLocalDeclarationPriority, - FilterText: ptrTo(".bar"), - InsertText: ptrTo(".bar"), - TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ - TextEdit: &lsproto.TextEdit{ - NewText: ".bar", - Range: lsproto.Range{ - Start: lsproto.Position{Line: 19, Character: 1}, - End: lsproto.Position{Line: 19, Character: 2}, - }, - }, - }, + Label: "bar", + Kind: methodKind, + SortText: sortTextLocalDeclarationPriority, }, { - Label: "bar2", - Kind: methodKind, - SortText: sortTextLocalDeclarationPriority, - FilterText: ptrTo(".bar2"), - InsertText: ptrTo(".bar2"), - TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ - TextEdit: &lsproto.TextEdit{ - NewText: ".bar2", - Range: lsproto.Range{ - Start: lsproto.Position{Line: 19, Character: 1}, - End: lsproto.Position{Line: 19, Character: 2}, - }, - }, - }, + Label: "bar2", + Kind: methodKind, + SortText: sortTextLocalDeclarationPriority, }, { - Label: "apply", - Kind: methodKind, - SortText: sortTextLocationPriority, - FilterText: ptrTo(".apply"), - InsertText: ptrTo(".apply"), - TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ - TextEdit: &lsproto.TextEdit{ - NewText: ".apply", - Range: lsproto.Range{ - Start: lsproto.Position{Line: 19, Character: 1}, - End: lsproto.Position{Line: 19, Character: 2}, - }, - }, - }, + Label: "apply", + Kind: methodKind, + SortText: sortTextLocationPriority, }, { - Label: "arguments", - Kind: fieldKind, - SortText: sortTextLocationPriority, - FilterText: ptrTo(".arguments"), - InsertText: ptrTo(".arguments"), - TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ - TextEdit: &lsproto.TextEdit{ - NewText: ".arguments", - Range: lsproto.Range{ - Start: lsproto.Position{Line: 19, Character: 1}, - End: lsproto.Position{Line: 19, Character: 2}, - }, - }, - }, + Label: "arguments", + Kind: fieldKind, + SortText: sortTextLocationPriority, }, { - Label: "baz", - Kind: functionKind, - SortText: sortTextLocationPriority, - FilterText: ptrTo(".baz"), - InsertText: ptrTo(".baz"), - TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ - TextEdit: &lsproto.TextEdit{ - NewText: ".baz", - Range: lsproto.Range{ - Start: lsproto.Position{Line: 19, Character: 1}, - End: lsproto.Position{Line: 19, Character: 2}, - }, - }, - }, + Label: "baz", + Kind: functionKind, + SortText: sortTextLocationPriority, }, { - Label: "bind", - Kind: methodKind, - SortText: sortTextLocationPriority, - FilterText: ptrTo(".bind"), - InsertText: ptrTo(".bind"), - TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ - TextEdit: &lsproto.TextEdit{ - NewText: ".bind", - Range: lsproto.Range{ - Start: lsproto.Position{Line: 19, Character: 1}, - End: lsproto.Position{Line: 19, Character: 2}, - }, - }, - }, + Label: "bind", + Kind: methodKind, + SortText: sortTextLocationPriority, }, { - Label: "call", - Kind: methodKind, - SortText: sortTextLocationPriority, - FilterText: ptrTo(".call"), - InsertText: ptrTo(".call"), - TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ - TextEdit: &lsproto.TextEdit{ - NewText: ".call", - Range: lsproto.Range{ - Start: lsproto.Position{Line: 19, Character: 1}, - End: lsproto.Position{Line: 19, Character: 2}, - }, - }, - }, + Label: "call", + Kind: methodKind, + SortText: sortTextLocationPriority, }, { - Label: "caller", - Kind: fieldKind, - SortText: sortTextLocationPriority, - FilterText: ptrTo(".caller"), - InsertText: ptrTo(".caller"), - TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ - TextEdit: &lsproto.TextEdit{ - NewText: ".caller", - Range: lsproto.Range{ - Start: lsproto.Position{Line: 19, Character: 1}, - End: lsproto.Position{Line: 19, Character: 2}, - }, - }, - }, + Label: "caller", + Kind: fieldKind, + SortText: sortTextLocationPriority, }, { - Label: "length", - Kind: fieldKind, - SortText: sortTextLocationPriority, - FilterText: ptrTo(".length"), - InsertText: ptrTo(".length"), - TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ - TextEdit: &lsproto.TextEdit{ - NewText: ".length", - Range: lsproto.Range{ - Start: lsproto.Position{Line: 19, Character: 1}, - End: lsproto.Position{Line: 19, Character: 2}, - }, - }, - }, + Label: "length", + Kind: fieldKind, + SortText: sortTextLocationPriority, }, { - Label: "prototype", - Kind: fieldKind, - SortText: sortTextLocationPriority, - FilterText: ptrTo(".prototype"), - InsertText: ptrTo(".prototype"), - TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ - TextEdit: &lsproto.TextEdit{ - NewText: ".prototype", - Range: lsproto.Range{ - Start: lsproto.Position{Line: 19, Character: 1}, - End: lsproto.Position{Line: 19, Character: 2}, - }, - }, - }, + Label: "prototype", + Kind: fieldKind, + SortText: sortTextLocationPriority, }, { - Label: "toString", - Kind: methodKind, - SortText: sortTextLocationPriority, - FilterText: ptrTo(".toString"), - InsertText: ptrTo(".toString"), - TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ - TextEdit: &lsproto.TextEdit{ - NewText: ".toString", - Range: lsproto.Range{ - Start: lsproto.Position{Line: 19, Character: 1}, - End: lsproto.Position{Line: 19, Character: 2}, - }, - }, - }, + Label: "toString", + Kind: methodKind, + SortText: sortTextLocationPriority, }, { - Label: "x", - Kind: variableKind, - SortText: sortTextLocationPriority, - FilterText: ptrTo(".x"), - InsertText: ptrTo(".x"), - TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ - TextEdit: &lsproto.TextEdit{ - NewText: ".x", - Range: lsproto.Range{ - Start: lsproto.Position{Line: 19, Character: 1}, - End: lsproto.Position{Line: 19, Character: 2}, - }, - }, - }, + Label: "x", + Kind: variableKind, + SortText: sortTextLocationPriority, }, }, }, @@ -555,36 +279,14 @@ D./*a*/`, ItemDefaults: itemDefaults, Items: []*lsproto.CompletionItem{ { - Label: "a", - Kind: fieldKind, - SortText: sortTextLocationPriority, - FilterText: ptrTo(".a"), - InsertText: ptrTo(".a"), - TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ - TextEdit: &lsproto.TextEdit{ - NewText: ".a", - Range: lsproto.Range{ - Start: lsproto.Position{Line: 4, Character: 16}, - End: lsproto.Position{Line: 4, Character: 17}, - }, - }, - }, + Label: "a", + Kind: fieldKind, + SortText: sortTextLocationPriority, }, { - Label: "b", - Kind: methodKind, - SortText: sortTextLocationPriority, - FilterText: ptrTo(".b"), - InsertText: ptrTo(".b"), - TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ - TextEdit: &lsproto.TextEdit{ - NewText: ".b", - Range: lsproto.Range{ - Start: lsproto.Position{Line: 4, Character: 16}, - End: lsproto.Position{Line: 4, Character: 17}, - }, - }, - }, + Label: "b", + Kind: methodKind, + SortText: sortTextLocationPriority, }, }, }, @@ -602,21 +304,7 @@ x.forEach(function (y) { y./*1*/`, list: &lsproto.CompletionList{ IsIncomplete: false, ItemDefaults: itemDefaults, - Items: core.Map(stringMembers, func(basicItem *lsproto.CompletionItem) *lsproto.CompletionItem { - item := *basicItem - item.FilterText = ptrTo("." + item.Label) - item.InsertText = item.FilterText - item.TextEdit = &lsproto.TextEditOrInsertReplaceEdit{ - TextEdit: &lsproto.TextEdit{ - NewText: *item.FilterText, - Range: lsproto.Range{ - Start: lsproto.Position{Line: 1, Character: 26}, - End: lsproto.Position{Line: 1, Character: 27}, - }, - }, - } - return &item - }), + Items: stringMembers, }, }, }, @@ -638,8 +326,7 @@ x./**/;`, Kind: fieldKind, SortText: sortTextLocationPriority, InsertText: ptrTo("[0]"), - - FilterText: ptrTo(".[0]"), + FilterText: ptrTo(".0"), TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ TextEdit: &lsproto.TextEdit{ NewText: "[0]", @@ -655,8 +342,7 @@ x./**/;`, Kind: fieldKind, SortText: sortTextLocationPriority, InsertText: ptrTo("[1]"), - - FilterText: ptrTo(".[1]"), + FilterText: ptrTo(".1"), TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ TextEdit: &lsproto.TextEdit{ NewText: "[1]", @@ -667,21 +353,7 @@ x./**/;`, }, }, }, - }, core.Map(arrayMembers, func(basicItem *lsproto.CompletionItem) *lsproto.CompletionItem { - item := *basicItem - item.FilterText = ptrTo("." + item.Label) - item.InsertText = item.FilterText - item.TextEdit = &lsproto.TextEditOrInsertReplaceEdit{ - TextEdit: &lsproto.TextEdit{ - NewText: *item.FilterText, - Range: lsproto.Range{ - Start: lsproto.Position{Line: 1, Character: 1}, - End: lsproto.Position{Line: 1, Character: 2}, - }, - }, - } - return &item - })...), + }, arrayMembers...), }, }, }, @@ -1693,20 +1365,9 @@ switch (x) { ItemDefaults: itemDefaults, Items: []*lsproto.CompletionItem{ { - Label: "B", - Kind: enumMemberKind, - SortText: sortTextLocationPriority, - InsertText: ptrTo(".B"), - FilterText: ptrTo(".B"), - TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ - TextEdit: &lsproto.TextEdit{ - NewText: ".B", - Range: lsproto.Range{ - Start: lsproto.Position{Line: 5, Character: 10}, - End: lsproto.Position{Line: 5, Character: 11}, - }, - }, - }, + Label: "B", + Kind: enumMemberKind, + SortText: sortTextLocationPriority, }, }, }, From 2fcbc8ee53b4b443adb16c7f5489a8a4f455fcf0 Mon Sep 17 00:00:00 2001 From: Gabriela Araujo Britto Date: Thu, 17 Jul 2025 15:05:39 -0700 Subject: [PATCH 5/7] update failing tests --- internal/fourslash/_scripts/failingTests.txt | 33 ------------------- ...ryForPropertyFromUnionOfModuleType_test.go | 2 +- ...istAfterRegularExpressionLiteral01_test.go | 2 +- ...ListAfterRegularExpressionLiteral1_test.go | 2 +- .../completionListAfterStringLiteral1_test.go | 2 +- .../tests/gen/completionListCladule_test.go | 2 +- .../tests/gen/completionListForRest_test.go | 2 +- .../gen/completionListObjectMembers_test.go | 2 +- ...ompletionListPrivateNamesAccessors_test.go | 2 +- .../completionListPrivateNamesMethods_test.go | 2 +- .../gen/completionListPrivateNames_test.go | 2 +- ...mpletionListStaticProtectedMembers_test.go | 2 +- ...nWithDotFollowedByNamespaceKeyword_test.go | 2 +- .../gen/completionsDefaultExport_test.go | 2 +- ...sECMAPrivateMemberTriggerCharacter_test.go | 2 +- .../gen/completionsECMAPrivateMember_test.go | 2 +- .../completionsOptionalKindModifier_test.go | 2 +- .../gen/completionsWithDeprecatedTag6_test.go | 2 +- .../gen/getJavaScriptCompletions11_test.go | 2 +- .../gen/getJavaScriptCompletions14_test.go | 2 +- .../gen/getJavaScriptCompletions19_test.go | 2 +- .../gen/getJavaScriptCompletions1_test.go | 2 +- .../gen/getJavaScriptCompletions2_test.go | 2 +- .../gen/getJavaScriptCompletions3_test.go | 2 +- .../gen/getJavaScriptCompletions4_test.go | 2 +- .../gen/getJavaScriptCompletions5_test.go | 2 +- .../tests/gen/javaScriptClass4_test.go | 2 +- .../gen/jsDocFunctionSignatures3_test.go | 2 +- .../tests/gen/jsDocGenerics1_test.go | 2 +- .../memberCompletionOnTypeParameters_test.go | 2 +- .../tests/gen/memberListErrorRecovery_test.go | 2 +- .../gen/memberListOnExplicitThis_test.go | 2 +- ...emberListOnThisInClassWithPrivates_test.go | 2 +- .../gen/moduleMembersOfGenericType_test.go | 2 +- 34 files changed, 33 insertions(+), 66 deletions(-) diff --git a/internal/fourslash/_scripts/failingTests.txt b/internal/fourslash/_scripts/failingTests.txt index d0a6d8a10b..d9ce854e86 100644 --- a/internal/fourslash/_scripts/failingTests.txt +++ b/internal/fourslash/_scripts/failingTests.txt @@ -8,7 +8,6 @@ TestCompletionEntryForArgumentConstrainedToString TestCompletionEntryForArrayElementConstrainedToString TestCompletionEntryForArrayElementConstrainedToString2 TestCompletionEntryForClassMembers_StaticWhenBaseTypeIsNotResolved -TestCompletionEntryForPropertyFromUnionOfModuleType TestCompletionEntryForUnionProperty TestCompletionEntryForUnionProperty2 TestCompletionExportFrom @@ -67,17 +66,12 @@ TestCompletionInNamedImportLocation TestCompletionInUncheckedJSFile TestCompletionInfoWithExplicitTypeArguments TestCompletionJSDocNamePath -TestCompletionListAfterRegularExpressionLiteral01 -TestCompletionListAfterRegularExpressionLiteral1 -TestCompletionListAfterStringLiteral1 TestCompletionListAndMemberListOnCommentedDot TestCompletionListAndMemberListOnCommentedWhiteSpace TestCompletionListBuilderLocations_VariableDeclarations -TestCompletionListCladule TestCompletionListClassMembers TestCompletionListForDerivedType1 TestCompletionListForExportEquals -TestCompletionListForRest TestCompletionListForTransitivelyExportedMembers01 TestCompletionListForTransitivelyExportedMembers04 TestCompletionListFunctionExpression @@ -107,16 +101,11 @@ TestCompletionListInUnclosedTemplate01 TestCompletionListInUnclosedTemplate02 TestCompletionListInvalidMemberNames2 TestCompletionListInvalidMemberNames_withExistingIdentifier -TestCompletionListObjectMembers TestCompletionListObjectMembersInTypeLocationWithTypeof TestCompletionListOfGenericSymbol TestCompletionListOnAliases TestCompletionListOnAliases2 -TestCompletionListPrivateNames -TestCompletionListPrivateNamesAccessors -TestCompletionListPrivateNamesMethods TestCompletionListStaticMembers -TestCompletionListStaticProtectedMembers TestCompletionListStaticProtectedMembers2 TestCompletionListStaticProtectedMembers3 TestCompletionListStringParenthesizedExpression @@ -130,13 +119,9 @@ TestCompletionOfAwaitPromise6 TestCompletionOfInterfaceAndVar TestCompletionPreferredSuggestions1 TestCompletionWithConditionalOperatorMissingColon -TestCompletionWithDotFollowedByNamespaceKeyword TestCompletionsAfterJSDoc TestCompletionsAugmentedTypesClass2 TestCompletionsBeforeRestArg1 -TestCompletionsDefaultExport -TestCompletionsECMAPrivateMember -TestCompletionsECMAPrivateMemberTriggerCharacter TestCompletionsExportImport TestCompletionsGenericTypeWithMultipleBases1 TestCompletionsInRequire @@ -159,7 +144,6 @@ TestCompletionsLiterals TestCompletionsMergedDeclarations1 TestCompletionsNamespaceMergedWithClass TestCompletionsNewTarget -TestCompletionsOptionalKindModifier TestCompletionsOptionalMethod TestCompletionsOverridingMethod1 TestCompletionsOverridingMethod10 @@ -188,7 +172,6 @@ TestCompletionsTriggerCharacter TestCompletionsTypeOnlyNamespace TestCompletionsUniqueSymbol1 TestCompletionsWithDeprecatedTag5 -TestCompletionsWithDeprecatedTag6 TestCompletionsWithStringReplacementMode1 TestDoubleUnderscoreCompletions TestExportDefaultClass @@ -207,21 +190,13 @@ TestFindAllRefsReExport_broken TestFindAllRefs_importType_typeofImport TestFindReferencesAfterEdit TestGenericTypeWithMultipleBases1MultiFile -TestGetJavaScriptCompletions1 TestGetJavaScriptCompletions10 -TestGetJavaScriptCompletions11 TestGetJavaScriptCompletions12 TestGetJavaScriptCompletions13 -TestGetJavaScriptCompletions14 TestGetJavaScriptCompletions15 TestGetJavaScriptCompletions18 -TestGetJavaScriptCompletions19 -TestGetJavaScriptCompletions2 TestGetJavaScriptCompletions20 TestGetJavaScriptCompletions21 -TestGetJavaScriptCompletions3 -TestGetJavaScriptCompletions4 -TestGetJavaScriptCompletions5 TestGetJavaScriptCompletions8 TestGetJavaScriptCompletions9 TestGetJavaScriptGlobalCompletions1 @@ -248,7 +223,6 @@ TestImportStatementCompletions4 TestImportStatementCompletions_noPatternAmbient TestImportStatementCompletions_pnpmTransitive TestImportTypeMemberCompletions -TestJavaScriptClass4 TestJavaScriptModules12 TestJavaScriptModules13 TestJavaScriptModules14 @@ -256,9 +230,7 @@ TestJavaScriptModules19 TestJavascriptModules20 TestJavascriptModules21 TestJavascriptModulesTypeImport -TestJsDocFunctionSignatures3 TestJsDocFunctionTypeCompletionsNoCrash -TestJsDocGenerics1 TestJsdocExtendsTagCompletion TestJsdocImplementsTagCompletion TestJsdocImportTagCompletion1 @@ -277,17 +249,12 @@ TestJsdocTypedefTagNamespace TestJsdocTypedefTagTypeExpressionCompletion TestJsxFindAllReferencesOnRuntimeImportWithPaths1 TestLocalGetReferences -TestMemberCompletionOnTypeParameters -TestMemberListErrorRecovery TestMemberListInReopenedEnum TestMemberListInWithBlock TestMemberListOfClass TestMemberListOfExportedClass TestMemberListOfModuleAfterInvalidCharater TestMemberListOnConstructorType -TestMemberListOnExplicitThis -TestMemberListOnThisInClassWithPrivates -TestModuleMembersOfGenericType TestNodeModulesImportCompletions1 TestPathCompletionsAllowModuleAugmentationExtensions TestPathCompletionsAllowTsExtensions diff --git a/internal/fourslash/tests/gen/completionEntryForPropertyFromUnionOfModuleType_test.go b/internal/fourslash/tests/gen/completionEntryForPropertyFromUnionOfModuleType_test.go index 03516f5217..ebbd786dcc 100644 --- a/internal/fourslash/tests/gen/completionEntryForPropertyFromUnionOfModuleType_test.go +++ b/internal/fourslash/tests/gen/completionEntryForPropertyFromUnionOfModuleType_test.go @@ -10,7 +10,7 @@ import ( func TestCompletionEntryForPropertyFromUnionOfModuleType(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `module E { export var n = 1; diff --git a/internal/fourslash/tests/gen/completionListAfterRegularExpressionLiteral01_test.go b/internal/fourslash/tests/gen/completionListAfterRegularExpressionLiteral01_test.go index 9f7c1892d0..e85d838bce 100644 --- a/internal/fourslash/tests/gen/completionListAfterRegularExpressionLiteral01_test.go +++ b/internal/fourslash/tests/gen/completionListAfterRegularExpressionLiteral01_test.go @@ -11,7 +11,7 @@ import ( func TestCompletionListAfterRegularExpressionLiteral01(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `let v = 100; /a/./**/` diff --git a/internal/fourslash/tests/gen/completionListAfterRegularExpressionLiteral1_test.go b/internal/fourslash/tests/gen/completionListAfterRegularExpressionLiteral1_test.go index 831c895057..be2818ae9a 100644 --- a/internal/fourslash/tests/gen/completionListAfterRegularExpressionLiteral1_test.go +++ b/internal/fourslash/tests/gen/completionListAfterRegularExpressionLiteral1_test.go @@ -11,7 +11,7 @@ import ( func TestCompletionListAfterRegularExpressionLiteral1(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `/a/./**/` f := fourslash.NewFourslash(t, nil /*capabilities*/, content) diff --git a/internal/fourslash/tests/gen/completionListAfterStringLiteral1_test.go b/internal/fourslash/tests/gen/completionListAfterStringLiteral1_test.go index 15fa5f4d69..d734a2f2eb 100644 --- a/internal/fourslash/tests/gen/completionListAfterStringLiteral1_test.go +++ b/internal/fourslash/tests/gen/completionListAfterStringLiteral1_test.go @@ -11,7 +11,7 @@ import ( func TestCompletionListAfterStringLiteral1(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `"a"./**/` f := fourslash.NewFourslash(t, nil /*capabilities*/, content) diff --git a/internal/fourslash/tests/gen/completionListCladule_test.go b/internal/fourslash/tests/gen/completionListCladule_test.go index 34e9df0831..641bebf9e7 100644 --- a/internal/fourslash/tests/gen/completionListCladule_test.go +++ b/internal/fourslash/tests/gen/completionListCladule_test.go @@ -11,7 +11,7 @@ import ( func TestCompletionListCladule(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `class Foo { doStuff(): number { return 0; } diff --git a/internal/fourslash/tests/gen/completionListForRest_test.go b/internal/fourslash/tests/gen/completionListForRest_test.go index 16716738c6..3466b7ca23 100644 --- a/internal/fourslash/tests/gen/completionListForRest_test.go +++ b/internal/fourslash/tests/gen/completionListForRest_test.go @@ -10,7 +10,7 @@ import ( func TestCompletionListForRest(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `interface Gen { x: number; diff --git a/internal/fourslash/tests/gen/completionListObjectMembers_test.go b/internal/fourslash/tests/gen/completionListObjectMembers_test.go index 4380587ddb..df36b52090 100644 --- a/internal/fourslash/tests/gen/completionListObjectMembers_test.go +++ b/internal/fourslash/tests/gen/completionListObjectMembers_test.go @@ -10,7 +10,7 @@ import ( func TestCompletionListObjectMembers(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = ` var object: { (bar: any): any; diff --git a/internal/fourslash/tests/gen/completionListPrivateNamesAccessors_test.go b/internal/fourslash/tests/gen/completionListPrivateNamesAccessors_test.go index 422108888b..cc9aa2a841 100644 --- a/internal/fourslash/tests/gen/completionListPrivateNamesAccessors_test.go +++ b/internal/fourslash/tests/gen/completionListPrivateNamesAccessors_test.go @@ -9,7 +9,7 @@ import ( func TestCompletionListPrivateNamesAccessors(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = ` class Foo { get #x() { return 1 }; diff --git a/internal/fourslash/tests/gen/completionListPrivateNamesMethods_test.go b/internal/fourslash/tests/gen/completionListPrivateNamesMethods_test.go index fff7f130dc..e5eebb605e 100644 --- a/internal/fourslash/tests/gen/completionListPrivateNamesMethods_test.go +++ b/internal/fourslash/tests/gen/completionListPrivateNamesMethods_test.go @@ -9,7 +9,7 @@ import ( func TestCompletionListPrivateNamesMethods(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = ` class Foo { #x() {}; diff --git a/internal/fourslash/tests/gen/completionListPrivateNames_test.go b/internal/fourslash/tests/gen/completionListPrivateNames_test.go index 14a351310b..df33f88f7c 100644 --- a/internal/fourslash/tests/gen/completionListPrivateNames_test.go +++ b/internal/fourslash/tests/gen/completionListPrivateNames_test.go @@ -9,7 +9,7 @@ import ( func TestCompletionListPrivateNames(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `class Foo { #x; diff --git a/internal/fourslash/tests/gen/completionListStaticProtectedMembers_test.go b/internal/fourslash/tests/gen/completionListStaticProtectedMembers_test.go index 98e63825f2..819dd6e811 100644 --- a/internal/fourslash/tests/gen/completionListStaticProtectedMembers_test.go +++ b/internal/fourslash/tests/gen/completionListStaticProtectedMembers_test.go @@ -11,7 +11,7 @@ import ( func TestCompletionListStaticProtectedMembers(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `class Base { private static privateMethod() { } diff --git a/internal/fourslash/tests/gen/completionWithDotFollowedByNamespaceKeyword_test.go b/internal/fourslash/tests/gen/completionWithDotFollowedByNamespaceKeyword_test.go index 7686b46a64..124a721ba3 100644 --- a/internal/fourslash/tests/gen/completionWithDotFollowedByNamespaceKeyword_test.go +++ b/internal/fourslash/tests/gen/completionWithDotFollowedByNamespaceKeyword_test.go @@ -10,7 +10,7 @@ import ( func TestCompletionWithDotFollowedByNamespaceKeyword(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `namespace A { function foo() { diff --git a/internal/fourslash/tests/gen/completionsDefaultExport_test.go b/internal/fourslash/tests/gen/completionsDefaultExport_test.go index 821ddced0a..063e16626b 100644 --- a/internal/fourslash/tests/gen/completionsDefaultExport_test.go +++ b/internal/fourslash/tests/gen/completionsDefaultExport_test.go @@ -10,7 +10,7 @@ import ( func TestCompletionsDefaultExport(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `// @Filename: /a.ts export default function f() {} diff --git a/internal/fourslash/tests/gen/completionsECMAPrivateMemberTriggerCharacter_test.go b/internal/fourslash/tests/gen/completionsECMAPrivateMemberTriggerCharacter_test.go index 3b7ca753c8..0ec30f1676 100644 --- a/internal/fourslash/tests/gen/completionsECMAPrivateMemberTriggerCharacter_test.go +++ b/internal/fourslash/tests/gen/completionsECMAPrivateMemberTriggerCharacter_test.go @@ -9,7 +9,7 @@ import ( func TestCompletionsECMAPrivateMemberTriggerCharacter(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `// @target: esnext class K { diff --git a/internal/fourslash/tests/gen/completionsECMAPrivateMember_test.go b/internal/fourslash/tests/gen/completionsECMAPrivateMember_test.go index 305d3f9826..02df10ef00 100644 --- a/internal/fourslash/tests/gen/completionsECMAPrivateMember_test.go +++ b/internal/fourslash/tests/gen/completionsECMAPrivateMember_test.go @@ -10,7 +10,7 @@ import ( func TestCompletionsECMAPrivateMember(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `// @target: esnext class K { diff --git a/internal/fourslash/tests/gen/completionsOptionalKindModifier_test.go b/internal/fourslash/tests/gen/completionsOptionalKindModifier_test.go index 6f8610fec0..7860c923d9 100644 --- a/internal/fourslash/tests/gen/completionsOptionalKindModifier_test.go +++ b/internal/fourslash/tests/gen/completionsOptionalKindModifier_test.go @@ -10,7 +10,7 @@ import ( func TestCompletionsOptionalKindModifier(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `interface A { a?: number; method?(): number; }; function f(x: A) { diff --git a/internal/fourslash/tests/gen/completionsWithDeprecatedTag6_test.go b/internal/fourslash/tests/gen/completionsWithDeprecatedTag6_test.go index d95b57597c..807922157b 100644 --- a/internal/fourslash/tests/gen/completionsWithDeprecatedTag6_test.go +++ b/internal/fourslash/tests/gen/completionsWithDeprecatedTag6_test.go @@ -11,7 +11,7 @@ import ( func TestCompletionsWithDeprecatedTag6(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `module Foo { /** @deprecated foo */ diff --git a/internal/fourslash/tests/gen/getJavaScriptCompletions11_test.go b/internal/fourslash/tests/gen/getJavaScriptCompletions11_test.go index 761e17341e..c13fb35c6d 100644 --- a/internal/fourslash/tests/gen/getJavaScriptCompletions11_test.go +++ b/internal/fourslash/tests/gen/getJavaScriptCompletions11_test.go @@ -10,7 +10,7 @@ import ( func TestGetJavaScriptCompletions11(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `// @allowNonTsExtensions: true // @Filename: Foo.js diff --git a/internal/fourslash/tests/gen/getJavaScriptCompletions14_test.go b/internal/fourslash/tests/gen/getJavaScriptCompletions14_test.go index 8fd728bc06..75fe911255 100644 --- a/internal/fourslash/tests/gen/getJavaScriptCompletions14_test.go +++ b/internal/fourslash/tests/gen/getJavaScriptCompletions14_test.go @@ -10,7 +10,7 @@ import ( func TestGetJavaScriptCompletions14(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `// @allowNonTsExtensions: true // @Filename: file1.js diff --git a/internal/fourslash/tests/gen/getJavaScriptCompletions19_test.go b/internal/fourslash/tests/gen/getJavaScriptCompletions19_test.go index 6330d7bd46..039d9c5b58 100644 --- a/internal/fourslash/tests/gen/getJavaScriptCompletions19_test.go +++ b/internal/fourslash/tests/gen/getJavaScriptCompletions19_test.go @@ -10,7 +10,7 @@ import ( func TestGetJavaScriptCompletions19(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `// @allowNonTsExtensions: true // @Filename: file.js diff --git a/internal/fourslash/tests/gen/getJavaScriptCompletions1_test.go b/internal/fourslash/tests/gen/getJavaScriptCompletions1_test.go index 48c2126203..decf19933d 100644 --- a/internal/fourslash/tests/gen/getJavaScriptCompletions1_test.go +++ b/internal/fourslash/tests/gen/getJavaScriptCompletions1_test.go @@ -10,7 +10,7 @@ import ( func TestGetJavaScriptCompletions1(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `// @allowNonTsExtensions: true // @Filename: Foo.js diff --git a/internal/fourslash/tests/gen/getJavaScriptCompletions2_test.go b/internal/fourslash/tests/gen/getJavaScriptCompletions2_test.go index d4f7a6b306..990557ef46 100644 --- a/internal/fourslash/tests/gen/getJavaScriptCompletions2_test.go +++ b/internal/fourslash/tests/gen/getJavaScriptCompletions2_test.go @@ -10,7 +10,7 @@ import ( func TestGetJavaScriptCompletions2(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `// @allowNonTsExtensions: true // @Filename: Foo.js diff --git a/internal/fourslash/tests/gen/getJavaScriptCompletions3_test.go b/internal/fourslash/tests/gen/getJavaScriptCompletions3_test.go index e8c8624012..ce5080767c 100644 --- a/internal/fourslash/tests/gen/getJavaScriptCompletions3_test.go +++ b/internal/fourslash/tests/gen/getJavaScriptCompletions3_test.go @@ -10,7 +10,7 @@ import ( func TestGetJavaScriptCompletions3(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `// @allowNonTsExtensions: true // @Filename: Foo.js diff --git a/internal/fourslash/tests/gen/getJavaScriptCompletions4_test.go b/internal/fourslash/tests/gen/getJavaScriptCompletions4_test.go index d93e2c4190..21b99b8d10 100644 --- a/internal/fourslash/tests/gen/getJavaScriptCompletions4_test.go +++ b/internal/fourslash/tests/gen/getJavaScriptCompletions4_test.go @@ -10,7 +10,7 @@ import ( func TestGetJavaScriptCompletions4(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `// @allowNonTsExtensions: true // @Filename: Foo.js diff --git a/internal/fourslash/tests/gen/getJavaScriptCompletions5_test.go b/internal/fourslash/tests/gen/getJavaScriptCompletions5_test.go index 2bc9c98289..b7306fe28d 100644 --- a/internal/fourslash/tests/gen/getJavaScriptCompletions5_test.go +++ b/internal/fourslash/tests/gen/getJavaScriptCompletions5_test.go @@ -10,7 +10,7 @@ import ( func TestGetJavaScriptCompletions5(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `// @allowNonTsExtensions: true // @Filename: Foo.js diff --git a/internal/fourslash/tests/gen/javaScriptClass4_test.go b/internal/fourslash/tests/gen/javaScriptClass4_test.go index 140944d65b..73927ea637 100644 --- a/internal/fourslash/tests/gen/javaScriptClass4_test.go +++ b/internal/fourslash/tests/gen/javaScriptClass4_test.go @@ -10,7 +10,7 @@ import ( func TestJavaScriptClass4(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `// @allowNonTsExtensions: true // @Filename: Foo.js diff --git a/internal/fourslash/tests/gen/jsDocFunctionSignatures3_test.go b/internal/fourslash/tests/gen/jsDocFunctionSignatures3_test.go index 517ce44e2d..f2b619b623 100644 --- a/internal/fourslash/tests/gen/jsDocFunctionSignatures3_test.go +++ b/internal/fourslash/tests/gen/jsDocFunctionSignatures3_test.go @@ -10,7 +10,7 @@ import ( func TestJsDocFunctionSignatures3(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `// @allowNonTsExtensions: true // @Filename: Foo.js diff --git a/internal/fourslash/tests/gen/jsDocGenerics1_test.go b/internal/fourslash/tests/gen/jsDocGenerics1_test.go index af3337504f..8228a0a34e 100644 --- a/internal/fourslash/tests/gen/jsDocGenerics1_test.go +++ b/internal/fourslash/tests/gen/jsDocGenerics1_test.go @@ -10,7 +10,7 @@ import ( func TestJsDocGenerics1(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `// @allowNonTsExtensions: true // @Filename: ref.d.ts diff --git a/internal/fourslash/tests/gen/memberCompletionOnTypeParameters_test.go b/internal/fourslash/tests/gen/memberCompletionOnTypeParameters_test.go index 5c438fd2af..5f6b82044c 100644 --- a/internal/fourslash/tests/gen/memberCompletionOnTypeParameters_test.go +++ b/internal/fourslash/tests/gen/memberCompletionOnTypeParameters_test.go @@ -10,7 +10,7 @@ import ( func TestMemberCompletionOnTypeParameters(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `interface IFoo { x: number; diff --git a/internal/fourslash/tests/gen/memberListErrorRecovery_test.go b/internal/fourslash/tests/gen/memberListErrorRecovery_test.go index 98e561a386..9e353a8f41 100644 --- a/internal/fourslash/tests/gen/memberListErrorRecovery_test.go +++ b/internal/fourslash/tests/gen/memberListErrorRecovery_test.go @@ -11,7 +11,7 @@ import ( func TestMemberListErrorRecovery(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `class Foo { static fun() { }; } diff --git a/internal/fourslash/tests/gen/memberListOnExplicitThis_test.go b/internal/fourslash/tests/gen/memberListOnExplicitThis_test.go index 21a71ac455..85b7c624fb 100644 --- a/internal/fourslash/tests/gen/memberListOnExplicitThis_test.go +++ b/internal/fourslash/tests/gen/memberListOnExplicitThis_test.go @@ -10,7 +10,7 @@ import ( func TestMemberListOnExplicitThis(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `interface Restricted { n: number; diff --git a/internal/fourslash/tests/gen/memberListOnThisInClassWithPrivates_test.go b/internal/fourslash/tests/gen/memberListOnThisInClassWithPrivates_test.go index 53d9b6f5ad..03ea32ab02 100644 --- a/internal/fourslash/tests/gen/memberListOnThisInClassWithPrivates_test.go +++ b/internal/fourslash/tests/gen/memberListOnThisInClassWithPrivates_test.go @@ -10,7 +10,7 @@ import ( func TestMemberListOnThisInClassWithPrivates(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `class C1 { public pubMeth() {this./**/} // test on 'this.' diff --git a/internal/fourslash/tests/gen/moduleMembersOfGenericType_test.go b/internal/fourslash/tests/gen/moduleMembersOfGenericType_test.go index a89961c0dc..a98a6a6075 100644 --- a/internal/fourslash/tests/gen/moduleMembersOfGenericType_test.go +++ b/internal/fourslash/tests/gen/moduleMembersOfGenericType_test.go @@ -10,7 +10,7 @@ import ( func TestModuleMembersOfGenericType(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `module M { export var x = (x: T) => x; From 2d80c44b7a644af2dc4671904171222ec3df2eb0 Mon Sep 17 00:00:00 2001 From: Gabriela Araujo Britto Date: Thu, 17 Jul 2025 15:16:22 -0700 Subject: [PATCH 6/7] remove unused baseline --- .../FindReferencesAfterEdit.baseline.jsonc | 36 ------------------- 1 file changed, 36 deletions(-) delete mode 100644 testdata/baselines/reference/fourslash/findAllRef/FindReferencesAfterEdit.baseline.jsonc diff --git a/testdata/baselines/reference/fourslash/findAllRef/FindReferencesAfterEdit.baseline.jsonc b/testdata/baselines/reference/fourslash/findAllRef/FindReferencesAfterEdit.baseline.jsonc deleted file mode 100644 index 9123c0f239..0000000000 --- a/testdata/baselines/reference/fourslash/findAllRef/FindReferencesAfterEdit.baseline.jsonc +++ /dev/null @@ -1,36 +0,0 @@ -// === findAllReferences === -// === /a.ts === - -// interface A { -// /*FIND ALL REFS*/[|foo|]: string; -// } - - -// === /b.ts === - -// /// -// -// -// function foo(x: A) { -// x.[|foo|] -// } - - - - -// === findAllReferences === -// === /a.ts === - -// interface A { -// [|foo|]: string; -// } - - -// === /b.ts === - -// /// -// -// -// function foo(x: A) { -// x./*FIND ALL REFS*/[|foo|] -// } From a03dd09b07f837e12411189573825f25aa9111f5 Mon Sep 17 00:00:00 2001 From: Gabriela Araujo Britto Date: Fri, 18 Jul 2025 13:09:43 -0700 Subject: [PATCH 7/7] rename function and fix comment --- internal/ls/completions.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/ls/completions.go b/internal/ls/completions.go index 5799f04b5c..f9c37c05f1 100644 --- a/internal/ls/completions.go +++ b/internal/ls/completions.go @@ -2058,9 +2058,9 @@ var wordSeparators = collections.NewSetFromItems( ';', ':', '\'', '"', ',', '.', '<', '>', '/', '?', ) -// Finds the range of the word that ends at the given position. -// e.g. for "abc def.ghi|jkl", the word range is "ghi" and the word start is 'g'. -func getWordRange(sourceFile *ast.SourceFile, position int) (wordSize int, wordStart rune) { +// Finds the length and first rune of the word that ends at the given position. +// e.g. for "abc def.ghi|jkl", the word length is 3 and the word start is 'g'. +func getWordLengthAndStart(sourceFile *ast.SourceFile, position int) (wordLength int, wordStart rune) { // !!! Port other case of vscode's `DEFAULT_WORD_REGEXP` that covers words that start like numbers, e.g. -123.456abcd. text := sourceFile.Text()[:position] totalSize := 0 @@ -4157,7 +4157,7 @@ func (l *LanguageService) createLSPCompletionItem( // Filter text // Ported from vscode ts extension. - wordSize, wordStart := getWordRange(file, position) + wordSize, wordStart := getWordLengthAndStart(file, position) dotAccessor := getDotAccessor(file, position-wordSize) if filterText == "" { filterText = getFilterText(file, position, insertText, name, wordStart, dotAccessor)