diff --git a/internal/fourslash/_scripts/manualTests.txt b/internal/fourslash/_scripts/manualTests.txt index 1571b91174..492e3ccf70 100644 --- a/internal/fourslash/_scripts/manualTests.txt +++ b/internal/fourslash/_scripts/manualTests.txt @@ -1 +1,4 @@ completionListInClosedFunction05 +completionsAtIncompleteObjectLiteralProperty +completionsSelfDeclaring1 +completionsWithDeprecatedTag4 diff --git a/internal/fourslash/tests/completionFilterText1_test.go b/internal/fourslash/tests/completionFilterText1_test.go index e47d82626a..6937e8dd48 100644 --- a/internal/fourslash/tests/completionFilterText1_test.go +++ b/internal/fourslash/tests/completionFilterText1_test.go @@ -149,10 +149,7 @@ class Foo8 { IsIncomplete: false, ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ CommitCharacters: &DefaultCommitCharacters, - EditRange: &fourslash.EditRange{ - Insert: f.Ranges()[3], - Replace: f.Ranges()[3], - }, + EditRange: Ignored, }, Items: &fourslash.CompletionsExpectedItems{ Includes: []fourslash.CompletionsExpectedItem{ @@ -161,7 +158,13 @@ class Foo8 { Kind: PtrTo(lsproto.CompletionItemKindField), SortText: PtrTo(string(ls.SortTextSuggestedClassMembers)), FilterText: PtrTo("bar"), - InsertText: PtrTo("this.#bar"), + TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ + InsertReplaceEdit: &lsproto.InsertReplaceEdit{ + NewText: "this.#bar", + Insert: f.Ranges()[3].LSRange, + Replace: f.Ranges()[3].LSRange, + }, + }, }, }, }, @@ -187,18 +190,21 @@ class Foo8 { IsIncomplete: false, ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ CommitCharacters: &DefaultCommitCharacters, - EditRange: &fourslash.EditRange{ - Insert: f.Ranges()[4], - Replace: f.Ranges()[4], - }, + EditRange: Ignored, }, Items: &fourslash.CompletionsExpectedItems{ Includes: []fourslash.CompletionsExpectedItem{ &lsproto.CompletionItem{ - Label: "#bar", - Kind: PtrTo(lsproto.CompletionItemKindField), - SortText: PtrTo(string(ls.SortTextSuggestedClassMembers)), - InsertText: PtrTo("this.#bar"), + Label: "#bar", + Kind: PtrTo(lsproto.CompletionItemKindField), + SortText: PtrTo(string(ls.SortTextSuggestedClassMembers)), + TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ + InsertReplaceEdit: &lsproto.InsertReplaceEdit{ + NewText: "this.#bar", + Insert: f.Ranges()[4].LSRange, + Replace: f.Ranges()[4].LSRange, + }, + }, }, }, }, @@ -207,18 +213,21 @@ class Foo8 { IsIncomplete: false, ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ CommitCharacters: &DefaultCommitCharacters, - EditRange: &fourslash.EditRange{ - Insert: f.Ranges()[5], - Replace: f.Ranges()[5], - }, + EditRange: Ignored, }, Items: &fourslash.CompletionsExpectedItems{ Includes: []fourslash.CompletionsExpectedItem{ &lsproto.CompletionItem{ - Label: "#bar", - Kind: PtrTo(lsproto.CompletionItemKindField), - SortText: PtrTo(string(ls.SortTextSuggestedClassMembers)), - InsertText: PtrTo("this.#bar"), + Label: "#bar", + Kind: PtrTo(lsproto.CompletionItemKindField), + SortText: PtrTo(string(ls.SortTextSuggestedClassMembers)), + TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ + InsertReplaceEdit: &lsproto.InsertReplaceEdit{ + NewText: "this.#bar", + Insert: f.Ranges()[5].LSRange, + Replace: f.Ranges()[5].LSRange, + }, + }, }, }, }, diff --git a/internal/fourslash/tests/gen/completionsAtIncompleteObjectLiteralProperty_test.go b/internal/fourslash/tests/manual/completionsAtIncompleteObjectLiteralProperty_test.go similarity index 83% rename from internal/fourslash/tests/gen/completionsAtIncompleteObjectLiteralProperty_test.go rename to internal/fourslash/tests/manual/completionsAtIncompleteObjectLiteralProperty_test.go index 8f287044ab..ac591f2d05 100644 --- a/internal/fourslash/tests/gen/completionsAtIncompleteObjectLiteralProperty_test.go +++ b/internal/fourslash/tests/manual/completionsAtIncompleteObjectLiteralProperty_test.go @@ -16,7 +16,7 @@ func TestCompletionsAtIncompleteObjectLiteralProperty(t *testing.T) { defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `// @noLib: true f({ - a/**/ + [|a|]/**/ xyz: ` + "`" + `` + "`" + `, }); declare function f(options: { abc?: number, xyz?: string }): void;` @@ -31,10 +31,16 @@ declare function f(options: { abc?: number, xyz?: string }): void;` Exact: []fourslash.CompletionsExpectedItem{ &lsproto.CompletionItem{ Label: "abc?", - InsertText: PtrTo("abc"), FilterText: PtrTo("abc"), Kind: PtrTo(lsproto.CompletionItemKindField), SortText: PtrTo(string(ls.SortTextOptionalMember)), + TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ + InsertReplaceEdit: &lsproto.InsertReplaceEdit{ + NewText: "abc", + Insert: f.Ranges()[0].LSRange, + Replace: f.Ranges()[0].LSRange, + }, + }, }, }, }, diff --git a/internal/fourslash/tests/gen/completionsSelfDeclaring1_test.go b/internal/fourslash/tests/manual/completionsSelfDeclaring1_test.go similarity index 83% rename from internal/fourslash/tests/gen/completionsSelfDeclaring1_test.go rename to internal/fourslash/tests/manual/completionsSelfDeclaring1_test.go index 711f1216ae..92fb5850b5 100644 --- a/internal/fourslash/tests/gen/completionsSelfDeclaring1_test.go +++ b/internal/fourslash/tests/manual/completionsSelfDeclaring1_test.go @@ -24,7 +24,7 @@ function test>(opt: T) { } test({ a: { keyPath: '', - a/**/ + [|a|]/**/ } })` f := fourslash.NewFourslash(t, nil /*capabilities*/, content) @@ -38,9 +38,15 @@ test({ Exact: []fourslash.CompletionsExpectedItem{ &lsproto.CompletionItem{ Label: "autoIncrement?", - InsertText: PtrTo("autoIncrement"), FilterText: PtrTo("autoIncrement"), SortText: PtrTo(string(ls.SortTextOptionalMember)), + TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ + InsertReplaceEdit: &lsproto.InsertReplaceEdit{ + NewText: "autoIncrement", + Insert: f.Ranges()[0].LSRange, + Replace: f.Ranges()[0].LSRange, + }, + }, }, }, }, diff --git a/internal/fourslash/tests/gen/completionsWithDeprecatedTag4_test.go b/internal/fourslash/tests/manual/completionsWithDeprecatedTag4_test.go similarity index 84% rename from internal/fourslash/tests/gen/completionsWithDeprecatedTag4_test.go rename to internal/fourslash/tests/manual/completionsWithDeprecatedTag4_test.go index 186f2c4577..dcac2132b3 100644 --- a/internal/fourslash/tests/gen/completionsWithDeprecatedTag4_test.go +++ b/internal/fourslash/tests/manual/completionsWithDeprecatedTag4_test.go @@ -16,7 +16,7 @@ func TestCompletionsWithDeprecatedTag4(t *testing.T) { defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `// @noLib: true f({ - a/**/ + [|a|]/**/ xyz: ` + "`" + `` + "`" + `, }); declare function f(options: { @@ -35,10 +35,16 @@ declare function f(options: { Exact: []fourslash.CompletionsExpectedItem{ &lsproto.CompletionItem{ Label: "abc?", - InsertText: PtrTo("abc"), FilterText: PtrTo("abc"), Kind: PtrTo(lsproto.CompletionItemKindField), SortText: PtrTo(string(ls.DeprecateSortText(ls.SortTextOptionalMember))), + TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ + InsertReplaceEdit: &lsproto.InsertReplaceEdit{ + NewText: "abc", + Insert: f.Ranges()[0].LSRange, + Replace: f.Ranges()[0].LSRange, + }, + }, }, }, }, diff --git a/internal/ls/completions.go b/internal/ls/completions.go index 8a40ca0793..f72de5f5c3 100644 --- a/internal/ls/completions.go +++ b/internal/ls/completions.go @@ -4005,6 +4005,20 @@ func (l *LanguageService) setItemDefaults( Replace: *optionalReplacementSpan, }, } + for _, item := range items { + // If `editRange` is set, `insertText` is ignored by the client, so we need to + // provide `textEdit` instead. + if item.InsertText != nil && item.TextEdit == nil { + item.TextEdit = &lsproto.TextEditOrInsertReplaceEdit{ + InsertReplaceEdit: &lsproto.InsertReplaceEdit{ + NewText: *item.InsertText, + Insert: insertRange, + Replace: *optionalReplacementSpan, + }, + } + item.InsertText = nil + } + } } else if clientSupportsItemInsertReplace(clientOptions) { for _, item := range items { if item.TextEdit == nil { diff --git a/internal/ls/completions_test.go b/internal/ls/completions_test.go index 7bede1bd38..f5c0090cbd 100644 --- a/internal/ls/completions_test.go +++ b/internal/ls/completions_test.go @@ -646,131 +646,6 @@ class bar5{ constructor(public /*constructorParameter1*/`, }, }, }, - { - name: "completionEntryForClassMembers_StaticWhenBaseTypeIsNotResolved", - files: map[string]string{ - defaultMainFileName: `import React from 'react' -class Slider extends React.Component { - static defau/**/ltProps = { - onMouseDown: () => { }, - onMouseUp: () => { }, - unit: 'px', - } - handleChange = () => 10; -}`, - "/node_modules/@types/react/index.d.ts": `export = React; -export as namespace React; -declare namespace React { - function createElement(): any; - interface Component

{ } - class Component { - static contextType?: any; - context: any; - constructor(props: Readonly

); - setState( - state: ((prevState: Readonly, props: Readonly

) => (Pick | S | null)) | (Pick | S | null), - callback?: () => void - ): void; - } -}`, - }, - expectedResult: map[string]*testCaseResult{ - "": { - list: &lsproto.CompletionList{ - IsIncomplete: false, - ItemDefaults: &lsproto.CompletionItemDefaults{ - CommitCharacters: &[]string{}, - EditRange: &lsproto.RangeOrEditRangeWithInsertReplace{ - EditRangeWithInsertReplace: &lsproto.EditRangeWithInsertReplace{ - Insert: lsproto.Range{ - Start: lsproto.Position{Line: 2, Character: 11}, - End: lsproto.Position{Line: 2, Character: 16}, - }, - Replace: lsproto.Range{ - Start: lsproto.Position{Line: 2, Character: 11}, - End: lsproto.Position{Line: 2, Character: 23}, - }, - }, - }, - }, - Items: []*lsproto.CompletionItem{ - { - Label: "contextType?", - Kind: fieldKind, - SortText: sortTextLocationPriority, - FilterText: ptrTo("contextType"), - InsertText: ptrTo("contextType"), - }, - { - Label: "abstract", - Kind: keywordKind, - SortText: sortTextGlobalsOrKeywords, - }, - { - Label: "accessor", - Kind: keywordKind, - SortText: sortTextGlobalsOrKeywords, - }, - { - Label: "async", - Kind: keywordKind, - SortText: sortTextGlobalsOrKeywords, - }, - { - Label: "constructor", - Kind: keywordKind, - SortText: sortTextGlobalsOrKeywords, - }, - { - Label: "declare", - Kind: keywordKind, - SortText: sortTextGlobalsOrKeywords, - }, - { - Label: "get", - Kind: keywordKind, - SortText: sortTextGlobalsOrKeywords, - }, - { - Label: "override", - Kind: keywordKind, - SortText: sortTextGlobalsOrKeywords, - }, - { - Label: "private", - Kind: keywordKind, - SortText: sortTextGlobalsOrKeywords, - }, - { - Label: "protected", - Kind: keywordKind, - SortText: sortTextGlobalsOrKeywords, - }, - { - Label: "public", - Kind: keywordKind, - SortText: sortTextGlobalsOrKeywords, - }, - { - Label: "readonly", - Kind: keywordKind, - SortText: sortTextGlobalsOrKeywords, - }, - { - Label: "set", - Kind: keywordKind, - SortText: sortTextGlobalsOrKeywords, - }, - { - Label: "static", - Kind: keywordKind, - SortText: sortTextGlobalsOrKeywords, - }, - }, - }, - }, - }, - }, { name: "completionsInJsxTag", mainFileName: "/index.tsx",