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
23 changes: 19 additions & 4 deletions internal/fourslash/_scripts/convertFourslash.mts
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,13 @@ function parseVerifyCompletionArg(arg: ts.Expression): VerifyCompletionsCmd | un
else if (init.getText() === "test.markers()") {
marker = "f.Markers()";
}
else if (
ts.isCallExpression(init)
&& init.expression.getText() === "test.marker"
&& ts.isStringLiteralLike(init.arguments[0])
) {
marker = getGoStringLiteral(init.arguments[0].text);
}
else {
console.error(`Unrecognized marker initializer: ${init.getText()}`);
return undefined;
Expand Down Expand Up @@ -511,7 +518,7 @@ function parseExpectedCompletionItem(expr: ts.Expression): string | undefined {
if (completionConstants.has(expr.getText())) {
return completionConstants.get(expr.getText())!;
}
if (ts.isStringLiteral(expr)) {
if (ts.isStringLiteralLike(expr)) {
return getGoStringLiteral(expr.text);
}
if (ts.isObjectLiteralExpression(expr)) {
Expand All @@ -531,7 +538,7 @@ function parseExpectedCompletionItem(expr: ts.Expression): string | undefined {
const init = prop.initializer;
switch (propName) {
case "name":
if (ts.isStringLiteral(init)) {
if (ts.isStringLiteralLike(init)) {
name = init.text;
}
else {
Expand All @@ -550,16 +557,19 @@ function parseExpectedCompletionItem(expr: ts.Expression): string | undefined {
}
break;
case "insertText":
if (ts.isStringLiteral(init)) {
if (ts.isStringLiteralLike(init)) {
insertText = init.text;
}
else if (init.getText() === "undefined") {
// Ignore
}
else {
console.error(`Expected string literal for insertText, got ${init.getText()}`);
return undefined;
}
break;
case "filterText":
if (ts.isStringLiteral(init)) {
if (ts.isStringLiteralLike(init)) {
filterText = init.text;
}
else {
Expand Down Expand Up @@ -609,6 +619,8 @@ function parseExpectedCompletionItem(expr: ts.Expression): string | undefined {
return undefined;
}
break;
case "isFromUncheckedFile":
break; // Ignored
case "commitCharacters":
case "replacementSpan":
// !!! support these later
Expand Down Expand Up @@ -742,6 +754,9 @@ function parseKindModifiers(expr: ts.Expression): { isOptional: boolean; isDepre
}

function parseSortText(expr: ts.Expression): string | undefined {
if (ts.isCallExpression(expr) && expr.expression.getText() === "completion.SortText.Deprecated") {
return `ls.DeprecateSortText(${parseSortText(expr.arguments[0])})`;
}
const text = expr.getText();
switch (text) {
case "completion.SortText.LocalDeclarationPriority":
Expand Down
11 changes: 11 additions & 0 deletions internal/fourslash/_scripts/failingTests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ TestCompletionInFunctionLikeBody_includesPrimitiveTypes
TestCompletionInJsDoc
TestCompletionInJsDocQualifiedNames
TestCompletionInNamedImportLocation
TestCompletionInUncheckedJSFile
TestCompletionInfoWithExplicitTypeArguments
TestCompletionListAfterRegularExpressionLiteral01
TestCompletionListAfterRegularExpressionLiteral1
TestCompletionListAfterStringLiteral1
TestCompletionListAndMemberListOnCommentedDot
TestCompletionListAndMemberListOnCommentedLine
TestCompletionListAndMemberListOnCommentedWhiteSpace
Expand Down Expand Up @@ -124,6 +128,7 @@ TestCompletionListStringParenthesizedExpression
TestCompletionListStringParenthesizedType
TestCompletionListWithoutVariableinitializer
TestCompletionListsStringLiteralTypeAsIndexedAccessTypeObject
TestCompletionNoAutoInsertQuestionDotForThis
TestCompletionNoAutoInsertQuestionDotForTypeParameter
TestCompletionNoAutoInsertQuestionDotWithUserPreferencesOff
TestCompletionOfAwaitPromise6
Expand All @@ -135,6 +140,7 @@ TestCompletionsAfterJSDoc
TestCompletionsAugmentedTypesClass2
TestCompletionsBeforeRestArg1
TestCompletionsDefaultExport
TestCompletionsECMAPrivateMember
TestCompletionsECMAPrivateMemberTriggerCharacter
TestCompletionsExportImport
TestCompletionsGenericTypeWithMultipleBases1
Expand Down Expand Up @@ -162,6 +168,8 @@ TestCompletionsNewTarget
TestCompletionsOptionalKindModifier
TestCompletionsOptionalMethod
TestCompletionsOverridingMethod1
TestCompletionsOverridingMethod10
TestCompletionsOverridingMethod11
TestCompletionsOverridingMethod14
TestCompletionsOverridingMethod17
TestCompletionsOverridingMethod3
Expand All @@ -185,6 +193,9 @@ TestCompletionsSymbolMembers
TestCompletionsTriggerCharacter
TestCompletionsTypeOnlyNamespace
TestCompletionsUniqueSymbol1
TestCompletionsWithDeprecatedTag5
TestCompletionsWithDeprecatedTag6
TestCompletionsWithDeprecatedTag9
TestCompletionsWithStringReplacementMode1
TestDoubleUnderscoreCompletions
TestExportDefaultClass
Expand Down
4 changes: 2 additions & 2 deletions internal/fourslash/fourslash.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func (f *FourslashTest) goToPosition(t *testing.T, position lsproto.Position) {
f.selectionEnd = nil
}

func (f *FourslashTest) GoToEachMarker(t *testing.T, markerNames []string, action func(t *testing.T, marker *Marker, index int)) {
func (f *FourslashTest) GoToEachMarker(t *testing.T, markerNames []string, action func(marker *Marker, index int)) {
var markers []*Marker
if len(markers) == 0 {
markers = f.Markers()
Expand All @@ -354,7 +354,7 @@ func (f *FourslashTest) GoToEachMarker(t *testing.T, markerNames []string, actio
}
for i, marker := range markers {
f.goToMarker(t, marker)
action(t, marker, i)
action(marker, i)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ f2</*1x*/T/*2x*/y/*3x*/, () =>/*4x*/T/*5x*/y/*6x*/
f2<() =>/*1y*/T/*2y*/y/*3y*/, () =>/*4y*/T/*5y*/y/*6y*/
f2<any, () =>/*1z*/T/*2z*/y/*3z*/`
f := fourslash.NewFourslash(t, nil /*capabilities*/, content)
f.GoToEachMarker(t, nil, func(t *testing.T, marker *fourslash.Marker, index int) {
f.GoToEachMarker(t, nil, func(marker *fourslash.Marker, index int) {
markerName := marker.Name
valueOnly := markerName != nil && strings.HasSuffix(*markerName, "ValueOnly")
commitCharacters := &defaultCommitCharacters
Expand Down
46 changes: 46 additions & 0 deletions internal/fourslash/tests/gen/completionInUncheckedJSFile_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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 TestCompletionInUncheckedJSFile(t *testing.T) {
t.Parallel()
t.Skip()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @allowJs: true
// @checkJs: false
// @Filename: index.js
function hello() {

}

const goodbye = 5;

console./*0*/`
f := fourslash.NewFourslash(t, nil /*capabilities*/, content)
f.VerifyCompletions(t, "0", &fourslash.CompletionsExpectedList{
IsIncomplete: false,
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
CommitCharacters: &defaultCommitCharacters,
EditRange: ignored,
},
Items: &fourslash.CompletionsExpectedItems{
Includes: []fourslash.CompletionsExpectedItem{
&lsproto.CompletionItem{
Label: "hello",
SortText: ptrTo(string(ls.SortTextJavascriptIdentifiers)),
},
&lsproto.CompletionItem{
Label: "goodbye",
SortText: ptrTo(string(ls.SortTextJavascriptIdentifiers)),
},
},
},
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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 TestCompletionListAfterRegularExpressionLiteral01(t *testing.T) {
t.Parallel()
t.Skip()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `let v = 100;
/a/./**/`
f := fourslash.NewFourslash(t, nil /*capabilities*/, content)
f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{
IsIncomplete: false,
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
CommitCharacters: &defaultCommitCharacters,
EditRange: ignored,
},
Items: &fourslash.CompletionsExpectedItems{
Unsorted: []fourslash.CompletionsExpectedItem{
"exec",
"test",
"source",
"global",
"ignoreCase",
"multiline",
"lastIndex",
&lsproto.CompletionItem{
Label: "compile",
SortText: ptrTo(string(ls.DeprecateSortText(ls.SortTextLocationPriority))),
},
},
},
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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 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)
f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{
IsIncomplete: false,
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
CommitCharacters: &defaultCommitCharacters,
EditRange: ignored,
},
Items: &fourslash.CompletionsExpectedItems{
Unsorted: []fourslash.CompletionsExpectedItem{
"exec",
"test",
"source",
"global",
"ignoreCase",
"multiline",
"lastIndex",
&lsproto.CompletionItem{
Label: "compile",
SortText: ptrTo(string(ls.DeprecateSortText(ls.SortTextLocationPriority))),
},
},
},
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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 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)
f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{
IsIncomplete: false,
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
CommitCharacters: &defaultCommitCharacters,
EditRange: ignored,
},
Items: &fourslash.CompletionsExpectedItems{
Unsorted: []fourslash.CompletionsExpectedItem{
"toString",
"charAt",
"charCodeAt",
"concat",
"indexOf",
"lastIndexOf",
"localeCompare",
"match",
"replace",
"search",
"slice",
"split",
"substring",
"toLowerCase",
"toLocaleLowerCase",
"toUpperCase",
"toLocaleUpperCase",
"trim",
"length",
&lsproto.CompletionItem{
Label: "substr",
SortText: ptrTo(string(ls.DeprecateSortText(ls.SortTextLocationPriority))),
},
"valueOf",
},
},
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package fourslash_test

import (
"testing"

"github.com/microsoft/typescript-go/internal/fourslash"
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
"github.com/microsoft/typescript-go/internal/testutil"
)

func TestCompletionNoAutoInsertQuestionDotForThis(t *testing.T) {
t.Parallel()
t.Skip()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @strict: true
class Address {
city: string = "";
"postal code": string = "";
method() {
this[|./**/|]
}
}`
f := fourslash.NewFourslash(t, nil /*capabilities*/, content)
f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{
IsIncomplete: false,
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
CommitCharacters: &defaultCommitCharacters,
EditRange: ignored,
},
Items: &fourslash.CompletionsExpectedItems{
Exact: []fourslash.CompletionsExpectedItem{
&lsproto.CompletionItem{
Label: "city",
Detail: ptrTo("(property) Address.city: string"),
},
&lsproto.CompletionItem{
Label: "method",
},
&lsproto.CompletionItem{
Label: "postal code",
InsertText: ptrTo("[\"postal code\"]"),
Detail: ptrTo("(property) Address[\"postal code\"]: string"),
},
},
},
})
}
Loading
Loading