Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/fourslash/_scripts/manualTests.txt
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
completionListInClosedFunction05
completionsAtIncompleteObjectLiteralProperty
completionsSelfDeclaring1
completionsWithDeprecatedTag4
51 changes: 30 additions & 21 deletions internal/fourslash/tests/completionFilterText1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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,
},
},
},
},
},
Expand All @@ -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,
},
},
},
},
},
Expand All @@ -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,
},
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;`
Expand All @@ -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,
},
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function test<T extends Record<string, Test>>(opt: T) { }
test({
a: {
keyPath: '',
a/**/
[|a|]/**/
}
})`
f := fourslash.NewFourslash(t, nil /*capabilities*/, content)
Expand All @@ -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,
},
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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,
},
},
},
},
},
Expand Down
14 changes: 14 additions & 0 deletions internal/ls/completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
125 changes: 0 additions & 125 deletions internal/ls/completions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,131 +646,6 @@ class bar5{ constructor(public /*constructorParameter1*/`,
},
},
},
{
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test file will be deleted as part of the snapshopt PR, and we also have fourslash tests now, so I just deleted this test case instead of updating it.

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<P = {}, S = {}, SS = any> { }
class Component<P, S> {
static contextType?: any;
context: any;
constructor(props: Readonly<P>);
setState<K extends keyof S>(
state: ((prevState: Readonly<S>, props: Readonly<P>) => (Pick<S, K> | S | null)) | (Pick<S, K> | 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",
Expand Down
Loading