From 16a22ea0a0cdfe1acc70625a55efaa00ab9f8629 Mon Sep 17 00:00:00 2001 From: Gabriela Araujo Britto Date: Fri, 27 Jun 2025 09:52:02 -0700 Subject: [PATCH 1/6] basic edit in fourslash --- internal/fourslash/fourslash.go | 186 +++++++++++++++++++-- internal/fourslash/tests/basicEdit_test.go | 53 ++++++ 2 files changed, 227 insertions(+), 12 deletions(-) create mode 100644 internal/fourslash/tests/basicEdit_test.go diff --git a/internal/fourslash/fourslash.go b/internal/fourslash/fourslash.go index 890abad8a1..3473e06481 100644 --- a/internal/fourslash/fourslash.go +++ b/internal/fourslash/fourslash.go @@ -19,6 +19,7 @@ import ( "github.com/microsoft/typescript-go/internal/project" "github.com/microsoft/typescript-go/internal/testutil/harnessutil" "github.com/microsoft/typescript-go/internal/tspath" + "github.com/microsoft/typescript-go/internal/vfs" "github.com/microsoft/typescript-go/internal/vfs/vfstest" "gotest.tools/v3/assert" ) @@ -28,15 +29,48 @@ type FourslashTest struct { in *lspWriter out *lspReader id int32 + vfs vfs.FS - testData *TestData + testData *TestData // !!! consolidate test files from test data and script info + + scriptInfos map[string]*scriptInfo + converters *ls.Converters currentCaretPosition lsproto.Position - currentFilename string lastKnownMarkerName string activeFilename string } +type scriptInfo struct { + fileName string + content string + lineMap *ls.LineMap + version int32 +} + +func newScriptInfo(fileName string, content string) *scriptInfo { + return &scriptInfo{ + fileName: fileName, + content: content, + lineMap: ls.ComputeLineStarts(content), + version: 1, + } +} + +func (s *scriptInfo) editContent(start int, end int, newText string) { + s.content = s.content[:start] + newText + s.content[end:] + s.lineMap = ls.ComputeLineStarts(s.content) + s.version++ +} + +func (s *scriptInfo) Text() string { + return s.content +} + +func (s *scriptInfo) FileName() string { + return s.fileName +} + type lspReader struct { c <-chan *lsproto.Message } @@ -101,10 +135,12 @@ func NewFourslash(t *testing.T, capabilities *lsproto.ClientCapabilities, conten rootDir := "/" fileName := getFileNameFromTest(t) testfs := make(map[string]string) + scriptInfos := make(map[string]*scriptInfo) testData := ParseTestData(t, content, fileName) for _, file := range testData.Files { filePath := tspath.GetNormalizedAbsolutePath(file.fileName, rootDir) testfs[filePath] = file.Content + scriptInfos[filePath] = newScriptInfo(filePath, file.Content) } compilerOptions := &core.CompilerOptions{} @@ -113,7 +149,7 @@ func NewFourslash(t *testing.T, capabilities *lsproto.ClientCapabilities, conten inputReader, inputWriter := newLSPPipe() outputReader, outputWriter := newLSPPipe() - fs := vfstest.FromMap(testfs, true /*useCaseSensitiveFileNames*/) + fs := bundled.WrapFS(vfstest.FromMap(testfs, true /*useCaseSensitiveFileNames*/)) var err strings.Builder server := lsp.NewServer(&lsp.ServerOptions{ @@ -123,7 +159,7 @@ func NewFourslash(t *testing.T, capabilities *lsproto.ClientCapabilities, conten Cwd: "/", NewLine: core.NewLineKindLF, - FS: bundled.WrapFS(fs), + FS: fs, DefaultLibraryPath: bundled.LibPath(), ParsedFileCache: &parsedFileCache{}, @@ -139,11 +175,22 @@ func NewFourslash(t *testing.T, capabilities *lsproto.ClientCapabilities, conten } }() + converters := ls.NewConverters(lsproto.PositionEncodingKindUTF8, func(fileName string) *ls.LineMap { + scriptInfo, ok := scriptInfos[fileName] + if !ok { + return nil + } + return scriptInfo.lineMap + }) + f := &FourslashTest{ - server: server, - in: inputWriter, - out: outputReader, - testData: &testData, + server: server, + in: inputWriter, + out: outputReader, + testData: &testData, + vfs: fs, + scriptInfos: scriptInfos, + converters: converters, } // !!! temporary; remove when we have `handleDidChangeConfiguration`/implicit project config support @@ -251,11 +298,22 @@ func (f *FourslashTest) GoToMarker(t *testing.T, markerName string) { t.Fatalf("Marker %s not found", markerName) } f.ensureActiveFile(t, marker.FileName) - f.currentCaretPosition = marker.LSPosition - f.currentFilename = marker.FileName + f.goToPosition(t, marker.LSPosition) f.lastKnownMarkerName = marker.Name } +func (f *FourslashTest) GoToEOF(t *testing.T) { + script := f.getScriptInfo(f.activeFilename) + pos := len(script.content) + LSPPos := f.converters.PositionToLineAndCharacter(script, core.TextPos(pos)) + f.goToPosition(t, LSPPos) +} + +func (f *FourslashTest) goToPosition(t *testing.T, position lsproto.Position) { + f.currentCaretPosition = position + // !!! clean up selection +} + func (f *FourslashTest) Markers() []*Marker { return f.testData.Markers } @@ -266,7 +324,7 @@ func (f *FourslashTest) Ranges() []*RangeMarker { func (f *FourslashTest) ensureActiveFile(t *testing.T, filename string) { if f.activeFilename != filename { - file := core.Find(f.testData.Files, func(f *TestFileInfo) bool { + file := core.Find(f.testData.Files, func(f *TestFileInfo) bool { // !!! use script info return f.fileName == filename }) if file == nil { @@ -378,7 +436,7 @@ func (f *FourslashTest) verifyCompletionsWorker(t *testing.T, expected *Completi params := &lsproto.CompletionParams{ TextDocumentPositionParams: lsproto.TextDocumentPositionParams{ TextDocument: lsproto.TextDocumentIdentifier{ - Uri: ls.FileNameToDocumentURI(f.currentFilename), + Uri: ls.FileNameToDocumentURI(f.activeFilename), }, Position: f.currentCaretPosition, }, @@ -561,3 +619,107 @@ func assertDeepEqual(t *testing.T, actual any, expected any, prefix string, opts func ptrTo[T any](v T) *T { return &v } + +// Insert text at the current caret position +func (f *FourslashTest) Insert(t *testing.T, text string) { + f.typeText(t, text) +} + +// Insert text and a new line at the current caret position +func (f *FourslashTest) InsertLine(t *testing.T, text string) { + f.typeText(t, text+"\n") +} + +func (f *FourslashTest) typeText(t *testing.T, text string) { + script := f.getScriptInfo(f.activeFilename) + offset := int(f.converters.LineAndCharacterToPosition(script, f.currentCaretPosition)) + // selection := f.getSelection() // !!! selection + // this.replace(selection.pos, selection.end - selection.pos, ""); // !!! selection + + totalSize := 0 + + for totalSize < len(text) { + r, size := utf8.DecodeRuneInString(text[totalSize:]) + f.editScriptAndUpdateMarkers(t, f.activeFilename, totalSize+offset, totalSize+offset, string(r)) + + totalSize += size + f.currentCaretPosition = f.converters.PositionToLineAndCharacter(script, core.TextPos(totalSize+offset)) + + // !!! formatting + // Handle post-keystroke formatting + // if this.enableFormatting { + // const edits = this.languageService.getFormattingEditsAfterKeystroke(this.activeFile.fileName, offset, ch, this.formatCodeSettings) + // if edits.length { + // offset += this.applyEdits(this.activeFile.fileName, edits) + // } + // } + + } + + // f.checkPostEditInvariants() // !!! do we need this? +} + +func (f *FourslashTest) editScriptAndUpdateMarkers(t *testing.T, fileName string, editStart int, editEnd int, newText string) { + script := f.editScript(t, fileName, editStart, editEnd, newText) + for _, marker := range f.testData.Markers { + if marker.FileName == fileName { + marker.Position = updatePosition(marker.Position, editStart, editEnd, newText) + marker.LSPosition = f.converters.PositionToLineAndCharacter(script, core.TextPos(marker.Position)) + } + } + for _, rangeMarker := range f.testData.Ranges { + if rangeMarker.FileName == fileName { + start := updatePosition(rangeMarker.Range.Pos(), editStart, editEnd, newText) + end := updatePosition(rangeMarker.Range.End(), editStart, editEnd, newText) + rangeMarker.Range = core.NewTextRange(start, end) + rangeMarker.LSRange = f.converters.ToLSPRange(script, rangeMarker.Range) + } + } + // !!! clean up ranges by text +} + +func updatePosition(pos int, editStart int, editEnd int, newText string) int { + if pos <= editStart { + return pos + } + // If inside the edit, return -1 to mark as invalid + if pos < editEnd { + return -1 + } + return pos + len(newText) - (editEnd - editStart) +} + +func (f *FourslashTest) editScript(t *testing.T, fileName string, start int, end int, newText string) *scriptInfo { + script := f.getScriptInfo(fileName) + changeRange := f.converters.ToLSPRange(script, core.NewTextRange(start, end)) + if script == nil { + panic(fmt.Sprintf("Script info for file %s not found", fileName)) + } + + script.editContent(start, end, newText) + err := f.vfs.WriteFile(fileName, script.content, false) + if err != nil { + panic(fmt.Sprintf("Failed to write file %s: %v", fileName, err)) + } + f.sendNotification(t, lsproto.MethodTextDocumentDidChange, &lsproto.DidChangeTextDocumentParams{ + TextDocument: lsproto.VersionedTextDocumentIdentifier{ + TextDocumentIdentifier: lsproto.TextDocumentIdentifier{ + Uri: ls.FileNameToDocumentURI(fileName), + }, + Version: script.version, + }, + ContentChanges: []lsproto.TextDocumentContentChangeEvent{ + { + TextDocumentContentChangePartial: &lsproto.TextDocumentContentChangePartial{ + Range: changeRange, + Text: newText, + }, + }, + }, + }) + return script +} + +func (f *FourslashTest) getScriptInfo(fileName string) *scriptInfo { + return f.scriptInfos[fileName] +} diff --git a/internal/fourslash/tests/basicEdit_test.go b/internal/fourslash/tests/basicEdit_test.go new file mode 100644 index 0000000000..bbd07cc72b --- /dev/null +++ b/internal/fourslash/tests/basicEdit_test.go @@ -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 TestBasicEdit(t *testing.T) { + t.Parallel() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `export {}; +interface Point { + x: number; + y: number; +} +declare const p: Point; +p/*a*/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "a") + f.Insert(t, ".") + f.GoToEOF(t) + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + }, + 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}, + }, + }, + }, + }, + "y", + }, + }, + }) +} From 860a4c269599f02512d7ac952e4336e4246f4f62 Mon Sep 17 00:00:00 2001 From: Gabriela Araujo Britto Date: Fri, 27 Jun 2025 10:54:52 -0700 Subject: [PATCH 2/6] backspace --- internal/fourslash/fourslash.go | 30 +++++++++++++- .../fourslash/tests/basicBackspace_test.go | 41 +++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 internal/fourslash/tests/basicBackspace_test.go diff --git a/internal/fourslash/fourslash.go b/internal/fourslash/fourslash.go index 3473e06481..ea9e512b05 100644 --- a/internal/fourslash/fourslash.go +++ b/internal/fourslash/fourslash.go @@ -620,16 +620,40 @@ func ptrTo[T any](v T) *T { return &v } -// Insert text at the current caret position +// Insert text at the current caret position. func (f *FourslashTest) Insert(t *testing.T, text string) { f.typeText(t, text) } -// Insert text and a new line at the current caret position +// Insert text and a new line at the current caret position. func (f *FourslashTest) InsertLine(t *testing.T, text string) { f.typeText(t, text+"\n") } +// Removes the text at the current caret position as if the user pressed backspace `count` times. +func (f *FourslashTest) Backspace(t *testing.T, count int) { + script := f.getScriptInfo(f.activeFilename) + offset := int(f.converters.LineAndCharacterToPosition(script, f.currentCaretPosition)) + + for range count { + offset-- + f.editScriptAndUpdateMarkers(t, f.activeFilename, offset, offset+1, "") + f.currentCaretPosition = f.converters.PositionToLineAndCharacter(script, core.TextPos(offset)) + // Don't need to examine formatting because there are no formatting changes on backspace. + } + + // f.checkPostEditInvariants() // !!! do we need this? +} + +// Enters text as if the user had pasted it. +func (f *FourslashTest) Paste(t *testing.T, text string) { + script := f.getScriptInfo(f.activeFilename) + start := int(f.converters.LineAndCharacterToPosition(script, f.currentCaretPosition)) + f.editScriptAndUpdateMarkers(t, f.activeFilename, start, start, text) + // this.checkPostEditInvariants(); +} + +// Inserts the text currently at the caret position character by character, as if the user typed it. func (f *FourslashTest) typeText(t *testing.T, text string) { script := f.getScriptInfo(f.activeFilename) offset := int(f.converters.LineAndCharacterToPosition(script, f.currentCaretPosition)) @@ -659,6 +683,8 @@ func (f *FourslashTest) typeText(t *testing.T, text string) { // f.checkPostEditInvariants() // !!! do we need this? } +// Edits the script and updates marker and range positions accordingly. +// This does not update the current caret position. func (f *FourslashTest) editScriptAndUpdateMarkers(t *testing.T, fileName string, editStart int, editEnd int, newText string) { script := f.editScript(t, fileName, editStart, editEnd, newText) for _, marker := range f.testData.Markers { diff --git a/internal/fourslash/tests/basicBackspace_test.go b/internal/fourslash/tests/basicBackspace_test.go new file mode 100644 index 0000000000..95162634e0 --- /dev/null +++ b/internal/fourslash/tests/basicBackspace_test.go @@ -0,0 +1,41 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestBasicBackspace(t *testing.T) { + t.Parallel() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `export {}; +interface Point { + x: number; + y: number;/*b*/ +} +declare const p: Point; +p./*a*/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "a", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{"y"}, + }, + }) + f.GoToMarker(t, "b") + f.Backspace(t, 10) // `y: number;` + f.VerifyCompletions(t, "a", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + }, + Items: &fourslash.CompletionsExpectedItems{ + Excludes: []string{"y"}, + }, + }) +} From 4905b29bddade492206be9c637ab0291fd3fefb8 Mon Sep 17 00:00:00 2001 From: Gabriela Araujo Britto Date: Fri, 27 Jun 2025 12:29:54 -0700 Subject: [PATCH 3/6] use script info to open file --- internal/fourslash/fourslash.go | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/internal/fourslash/fourslash.go b/internal/fourslash/fourslash.go index ea9e512b05..3f0ffbf34a 100644 --- a/internal/fourslash/fourslash.go +++ b/internal/fourslash/fourslash.go @@ -197,7 +197,7 @@ func NewFourslash(t *testing.T, capabilities *lsproto.ClientCapabilities, conten // !!! replace with a proper request *after initialize* f.server.SetCompilerOptionsForInferredProjects(compilerOptions) f.initialize(t, capabilities) - f.openFile(t, f.testData.Files[0]) + f.openFile(t, f.testData.Files[0].fileName) t.Cleanup(func() { inputWriter.Close() @@ -324,23 +324,21 @@ func (f *FourslashTest) Ranges() []*RangeMarker { func (f *FourslashTest) ensureActiveFile(t *testing.T, filename string) { if f.activeFilename != filename { - file := core.Find(f.testData.Files, func(f *TestFileInfo) bool { // !!! use script info - return f.fileName == filename - }) - if file == nil { - t.Fatalf("File %s not found in test data", filename) - } - f.openFile(t, file) + f.openFile(t, filename) } } -func (f *FourslashTest) openFile(t *testing.T, file *TestFileInfo) { - f.activeFilename = file.fileName +func (f *FourslashTest) openFile(t *testing.T, filename string) { + script := f.getScriptInfo(filename) + if script == nil { + t.Fatalf("File %s not found in test data", filename) + } + f.activeFilename = filename f.sendNotification(t, lsproto.MethodTextDocumentDidOpen, &lsproto.DidOpenTextDocumentParams{ TextDocument: &lsproto.TextDocumentItem{ - Uri: ls.FileNameToDocumentURI(file.fileName), - LanguageId: getLanguageKind(file.fileName), - Text: file.Content, + Uri: ls.FileNameToDocumentURI(filename), + LanguageId: getLanguageKind(filename), + Text: script.content, }, }) } From 98fbd1874bded2ad1b9c60761508076d5837acc1 Mon Sep 17 00:00:00 2001 From: Gabriela Araujo Britto Date: Fri, 27 Jun 2025 13:20:06 -0700 Subject: [PATCH 4/6] replaceLine + selection --- internal/fourslash/fourslash.go | 49 +++++++++++++++++-- .../fourslash/tests/basicReplaceLine_test.go | 41 ++++++++++++++++ 2 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 internal/fourslash/tests/basicReplaceLine_test.go diff --git a/internal/fourslash/fourslash.go b/internal/fourslash/fourslash.go index 3f0ffbf34a..d9c5b9b9ff 100644 --- a/internal/fourslash/fourslash.go +++ b/internal/fourslash/fourslash.go @@ -39,6 +39,7 @@ type FourslashTest struct { currentCaretPosition lsproto.Position lastKnownMarkerName string activeFilename string + selectionEnd *lsproto.Position } type scriptInfo struct { @@ -311,7 +312,7 @@ func (f *FourslashTest) GoToEOF(t *testing.T) { func (f *FourslashTest) goToPosition(t *testing.T, position lsproto.Position) { f.currentCaretPosition = position - // !!! clean up selection + f.selectionEnd = nil } func (f *FourslashTest) Markers() []*Marker { @@ -648,15 +649,55 @@ func (f *FourslashTest) Paste(t *testing.T, text string) { script := f.getScriptInfo(f.activeFilename) start := int(f.converters.LineAndCharacterToPosition(script, f.currentCaretPosition)) f.editScriptAndUpdateMarkers(t, f.activeFilename, start, start, text) - // this.checkPostEditInvariants(); + // this.checkPostEditInvariants(); // !!! do we need this? +} + +// Selects a line and replaces it with a new text. +func (f *FourslashTest) ReplaceLine(t *testing.T, lineIndex int, text string) { + f.selectLine(t, lineIndex) + f.typeText(t, text) +} + +func (f *FourslashTest) selectLine(t *testing.T, lineIndex int) { + script := f.getScriptInfo(f.activeFilename) + start := script.lineMap.LineStarts[lineIndex] + end := script.lineMap.LineStarts[lineIndex+1] - 1 + f.selectRange(t, core.NewTextRange(int(start), int(end))) +} + +func (f *FourslashTest) selectRange(t *testing.T, textRange core.TextRange) { + script := f.getScriptInfo(f.activeFilename) + start := f.converters.PositionToLineAndCharacter(script, core.TextPos(textRange.Pos())) + end := f.converters.PositionToLineAndCharacter(script, core.TextPos(textRange.End())) + f.goToPosition(t, start) + f.selectionEnd = &end +} + +func (f *FourslashTest) getSelection() core.TextRange { + script := f.getScriptInfo(f.activeFilename) + if f.selectionEnd == nil { + return core.NewTextRange( + int(f.converters.LineAndCharacterToPosition(script, f.currentCaretPosition)), + int(f.converters.LineAndCharacterToPosition(script, f.currentCaretPosition)), + ) + } + return core.NewTextRange( + int(f.converters.LineAndCharacterToPosition(script, f.currentCaretPosition)), + int(f.converters.LineAndCharacterToPosition(script, *f.selectionEnd)), + ) +} + +func (f *FourslashTest) Replace(t *testing.T, start int, length int, text string) { + f.editScriptAndUpdateMarkers(t, f.activeFilename, start, start+length, text) + // f.checkPostEditInvariants() // !!! do we need this? } // Inserts the text currently at the caret position character by character, as if the user typed it. func (f *FourslashTest) typeText(t *testing.T, text string) { script := f.getScriptInfo(f.activeFilename) offset := int(f.converters.LineAndCharacterToPosition(script, f.currentCaretPosition)) - // selection := f.getSelection() // !!! selection - // this.replace(selection.pos, selection.end - selection.pos, ""); // !!! selection + selection := f.getSelection() + f.Replace(t, selection.Pos(), selection.End()-selection.Pos(), "") totalSize := 0 diff --git a/internal/fourslash/tests/basicReplaceLine_test.go b/internal/fourslash/tests/basicReplaceLine_test.go new file mode 100644 index 0000000000..c4116bc0f9 --- /dev/null +++ b/internal/fourslash/tests/basicReplaceLine_test.go @@ -0,0 +1,41 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestBasicReplaceLine(t *testing.T) { + t.Parallel() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `export {}; +interface Point { + x: number; + y: number; +} +declare const p: Point; +p./*a*/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "a", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{"y"}, + }, + }) + f.ReplaceLine(t, 3, " z: number;") // `y: number;` + f.VerifyCompletions(t, "a", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + }, + Items: &fourslash.CompletionsExpectedItems{ + Excludes: []string{"y"}, + Includes: []fourslash.CompletionsExpectedItem{"z"}, + }, + }) +} From bf636bcf7204f74aee4e3c4b08bf01835ac7b140 Mon Sep 17 00:00:00 2001 From: Gabriela Araujo Britto Date: Fri, 27 Jun 2025 16:04:08 -0700 Subject: [PATCH 5/6] convert edit commands --- .../fourslash/_scripts/convertFourslash.mts | 61 ++++++++++++++- internal/fourslash/_scripts/failingTests.txt | 24 ++++++ .../tests/gen/addDeclareToModule_test.go | 20 +++++ .../tests/gen/addSignaturePartial_test.go | 18 +++++ .../gen/completionListAfterFunction2_test.go | 50 ++++++++++++ .../tests/gen/completionListCladule_test.go | 55 +++++++++++++ .../completionListFunctionExpression_test.go | 40 ++++++++++ ...ompletionListInFunctionDeclaration_test.go | 37 +++++++++ ...ctLiteralsWithPartialPropertyNames_test.go | 65 ++++++++++++++++ ...tionListInUnclosedIndexSignature02_test.go | 40 ++++++++++ .../fourslash/tests/gen/completions01_test.go | 43 ++++++++++ ...ResolutionOrderInImportDeclaration_test.go | 38 +++++++++ ...mpletionsImport_computedSymbolName_test.go | 44 +++++++++++ .../gen/completionsLiteralOverload_test.go | 51 ++++++++++++ .../completionsWritingSpreadArgument_test.go | 33 ++++++++ .../tests/gen/editTemplateConstraint_test.go | 22 ++++++ .../gen/getJavaScriptCompletions18_test.go | 50 ++++++++++++ .../gen/getJavaScriptCompletions19_test.go | 55 +++++++++++++ .../gen/getJavaScriptCompletions22_test.go | 22 ++++++ .../tests/gen/getJavaScriptQuickInfo8_test.go | 59 ++++++++++++++ ...ncrementalParsingInsertIntoMethod1_test.go | 24 ++++++ .../gen/jsDocFunctionSignatures3_test.go | 61 +++++++++++++++ .../pathCompletionsAllowTsExtensions_test.go | 53 +++++++++++++ ...letionsPackageJsonExportsWildcard2_test.go | 65 ++++++++++++++++ ...letionsPackageJsonExportsWildcard3_test.go | 57 ++++++++++++++ ...letionsPackageJsonExportsWildcard4_test.go | 71 +++++++++++++++++ ...ckageJsonImportsSrcNoDistWildcard2_test.go | 72 +++++++++++++++++ ...ckageJsonImportsSrcNoDistWildcard3_test.go | 65 ++++++++++++++++ ...ckageJsonImportsSrcNoDistWildcard4_test.go | 78 +++++++++++++++++++ ...letionsPackageJsonImportsWildcard2_test.go | 65 ++++++++++++++++ ...letionsPackageJsonImportsWildcard3_test.go | 57 ++++++++++++++ ...letionsPackageJsonImportsWildcard4_test.go | 71 +++++++++++++++++ ...hCompletionsTypesVersionsWildcard1_test.go | 56 +++++++++++++ ...hCompletionsTypesVersionsWildcard3_test.go | 67 ++++++++++++++++ ...hCompletionsTypesVersionsWildcard4_test.go | 56 +++++++++++++ ...hCompletionsTypesVersionsWildcard5_test.go | 72 +++++++++++++++++ ...hCompletionsTypesVersionsWildcard6_test.go | 72 +++++++++++++++++ .../propertyDuplicateIdentifierError_test.go | 21 +++++ .../tests/gen/regexErrorRecovery_test.go | 22 ++++++ .../tests/gen/superCallError0_test.go | 25 ++++++ .../tests/gen/syntaxErrorAfterImport1_test.go | 27 +++++++ ...peCheckAfterAddingGenericParameter_test.go | 31 ++++++++ .../updateSourceFile_jsdocSignature_test.go | 22 ++++++ 43 files changed, 2036 insertions(+), 1 deletion(-) create mode 100644 internal/fourslash/tests/gen/addDeclareToModule_test.go create mode 100644 internal/fourslash/tests/gen/addSignaturePartial_test.go create mode 100644 internal/fourslash/tests/gen/completionListAfterFunction2_test.go create mode 100644 internal/fourslash/tests/gen/completionListCladule_test.go create mode 100644 internal/fourslash/tests/gen/completionListFunctionExpression_test.go create mode 100644 internal/fourslash/tests/gen/completionListInFunctionDeclaration_test.go create mode 100644 internal/fourslash/tests/gen/completionListInTypedObjectLiteralsWithPartialPropertyNames_test.go create mode 100644 internal/fourslash/tests/gen/completionListInUnclosedIndexSignature02_test.go create mode 100644 internal/fourslash/tests/gen/completions01_test.go create mode 100644 internal/fourslash/tests/gen/completionsExternalModuleReferenceResolutionOrderInImportDeclaration_test.go create mode 100644 internal/fourslash/tests/gen/completionsImport_computedSymbolName_test.go create mode 100644 internal/fourslash/tests/gen/completionsLiteralOverload_test.go create mode 100644 internal/fourslash/tests/gen/completionsWritingSpreadArgument_test.go create mode 100644 internal/fourslash/tests/gen/editTemplateConstraint_test.go create mode 100644 internal/fourslash/tests/gen/getJavaScriptCompletions18_test.go create mode 100644 internal/fourslash/tests/gen/getJavaScriptCompletions19_test.go create mode 100644 internal/fourslash/tests/gen/getJavaScriptCompletions22_test.go create mode 100644 internal/fourslash/tests/gen/getJavaScriptQuickInfo8_test.go create mode 100644 internal/fourslash/tests/gen/incrementalParsingInsertIntoMethod1_test.go create mode 100644 internal/fourslash/tests/gen/jsDocFunctionSignatures3_test.go create mode 100644 internal/fourslash/tests/gen/pathCompletionsAllowTsExtensions_test.go create mode 100644 internal/fourslash/tests/gen/pathCompletionsPackageJsonExportsWildcard2_test.go create mode 100644 internal/fourslash/tests/gen/pathCompletionsPackageJsonExportsWildcard3_test.go create mode 100644 internal/fourslash/tests/gen/pathCompletionsPackageJsonExportsWildcard4_test.go create mode 100644 internal/fourslash/tests/gen/pathCompletionsPackageJsonImportsSrcNoDistWildcard2_test.go create mode 100644 internal/fourslash/tests/gen/pathCompletionsPackageJsonImportsSrcNoDistWildcard3_test.go create mode 100644 internal/fourslash/tests/gen/pathCompletionsPackageJsonImportsSrcNoDistWildcard4_test.go create mode 100644 internal/fourslash/tests/gen/pathCompletionsPackageJsonImportsWildcard2_test.go create mode 100644 internal/fourslash/tests/gen/pathCompletionsPackageJsonImportsWildcard3_test.go create mode 100644 internal/fourslash/tests/gen/pathCompletionsPackageJsonImportsWildcard4_test.go create mode 100644 internal/fourslash/tests/gen/pathCompletionsTypesVersionsWildcard1_test.go create mode 100644 internal/fourslash/tests/gen/pathCompletionsTypesVersionsWildcard3_test.go create mode 100644 internal/fourslash/tests/gen/pathCompletionsTypesVersionsWildcard4_test.go create mode 100644 internal/fourslash/tests/gen/pathCompletionsTypesVersionsWildcard5_test.go create mode 100644 internal/fourslash/tests/gen/pathCompletionsTypesVersionsWildcard6_test.go create mode 100644 internal/fourslash/tests/gen/propertyDuplicateIdentifierError_test.go create mode 100644 internal/fourslash/tests/gen/regexErrorRecovery_test.go create mode 100644 internal/fourslash/tests/gen/superCallError0_test.go create mode 100644 internal/fourslash/tests/gen/syntaxErrorAfterImport1_test.go create mode 100644 internal/fourslash/tests/gen/typeCheckAfterAddingGenericParameter_test.go create mode 100644 internal/fourslash/tests/gen/updateSourceFile_jsdocSignature_test.go diff --git a/internal/fourslash/_scripts/convertFourslash.mts b/internal/fourslash/_scripts/convertFourslash.mts index 1cc7a5d3eb..e099c59f0e 100644 --- a/internal/fourslash/_scripts/convertFourslash.mts +++ b/internal/fourslash/_scripts/convertFourslash.mts @@ -146,12 +146,64 @@ function parseFourslashStatement(statement: ts.Statement): Cmd[] | undefined { if (namespace.text === "goTo" && func.text === "marker") { return parseGoToMarkerArgs(callExpression.arguments); } + // `edit....` + if (namespace.text === "edit") { + const result = parseEditStatement(func.text, callExpression.arguments); + if (!result) { + return undefined; + } + return [result]; + } // !!! other fourslash commands } console.error(`Unrecognized fourslash statement: ${statement.getText()}`); return undefined; } +function parseEditStatement(funcName: string, args: readonly ts.Expression[]): EditCmd | undefined { + switch (funcName) { + case "insert": + case "paste": + case "insertLine": + if (args.length !== 1 || !ts.isStringLiteralLike(args[0])) { + console.error(`Expected a single string literal argument in edit.${funcName}, got ${args.map(arg => arg.getText()).join(", ")}`); + return undefined; + } + return { + kind: "edit", + goStatement: `f.${funcName.charAt(0).toUpperCase() + funcName.slice(1)}(t, ${getGoStringLiteral(args[0].text)})`, + }; + case "replaceLine": + if (args.length !== 2 || !ts.isNumericLiteral(args[0]) || !ts.isStringLiteral(args[1])) { + console.error(`Expected a single string literal argument in edit.insert, got ${args.map(arg => arg.getText()).join(", ")}`); + return undefined; + } + return { + kind: "edit", + goStatement: `f.ReplaceLine(t, ${args[0].text}, ${getGoStringLiteral(args[1].text)})`, + }; + case "backspace": + const arg = args[0]; + if (arg) { + if (!ts.isNumericLiteral(arg)) { + console.error(`Expected numeric literal argument in edit.backspace, got ${arg.getText()}`); + return undefined; + } + return { + kind: "edit", + goStatement: `f.Backspace(t, ${arg.text})`, + }; + } + return { + kind: "edit", + goStatement: `f.Backspace(t, 1)`, + }; + default: + console.error(`Unrecognized edit function: ${funcName}`); + return undefined; + } +} + function getGoStringLiteral(text: string): string { return `${JSON.stringify(text)}`; } @@ -614,7 +666,12 @@ interface GoToMarkerCmd { marker: string; } -type Cmd = VerifyCompletionsCmd | GoToMarkerCmd; +interface EditCmd { + kind: "edit"; + goStatement: string; +} + +type Cmd = VerifyCompletionsCmd | GoToMarkerCmd | EditCmd; function generateVerifyCompletions({ marker, args, isNewIdentifierLocation }: VerifyCompletionsCmd): string { let expectedList = "nil"; @@ -649,6 +706,8 @@ function generateCmd(cmd: Cmd): string { return generateVerifyCompletions(cmd as VerifyCompletionsCmd); case "goToMarker": return generateGoToMarker(cmd as GoToMarkerCmd); + case "edit": + return cmd.goStatement; default: throw new Error(`Unknown command kind: ${cmd}`); } diff --git a/internal/fourslash/_scripts/failingTests.txt b/internal/fourslash/_scripts/failingTests.txt index 1871713615..87be11ba0f 100644 --- a/internal/fourslash/_scripts/failingTests.txt +++ b/internal/fourslash/_scripts/failingTests.txt @@ -62,10 +62,12 @@ TestCompletionListAndMemberListOnCommentedLine TestCompletionListAndMemberListOnCommentedWhiteSpace TestCompletionListAtInvalidLocations TestCompletionListBuilderLocations_VariableDeclarations +TestCompletionListCladule TestCompletionListForExportEquals TestCompletionListForTransitivelyExportedMembers01 TestCompletionListForTransitivelyExportedMembers04 TestCompletionListForUnicodeEscapeName +TestCompletionListFunctionExpression TestCompletionListFunctionMembers TestCompletionListInArrowFunctionInUnclosedCallSite01 TestCompletionListInClassStaticBlocks @@ -74,6 +76,7 @@ TestCompletionListInComments TestCompletionListInComments2 TestCompletionListInComments3 TestCompletionListInExtendsClause +TestCompletionListInFunctionDeclaration TestCompletionListInImportClause01 TestCompletionListInImportClause05 TestCompletionListInImportClause06 @@ -108,6 +111,7 @@ TestCompletionsAfterJSDoc TestCompletionsBeforeRestArg1 TestCompletionsECMAPrivateMemberTriggerCharacter TestCompletionsImportDefaultExportCrash1 +TestCompletionsImport_computedSymbolName TestCompletionsImport_umdDefaultNoCrash2 TestCompletionsInRequire TestCompletionsInterfaceElement @@ -161,15 +165,19 @@ TestGetJavaScriptCompletions12 TestGetJavaScriptCompletions13 TestGetJavaScriptCompletions14 TestGetJavaScriptCompletions15 +TestGetJavaScriptCompletions18 +TestGetJavaScriptCompletions19 TestGetJavaScriptCompletions2 TestGetJavaScriptCompletions20 TestGetJavaScriptCompletions21 +TestGetJavaScriptCompletions22 TestGetJavaScriptCompletions3 TestGetJavaScriptCompletions4 TestGetJavaScriptCompletions5 TestGetJavaScriptCompletions8 TestGetJavaScriptCompletions9 TestGetJavaScriptGlobalCompletions1 +TestGetJavaScriptQuickInfo8 TestImportCompletionsPackageJsonExportsSpecifierEndsInTs TestImportCompletionsPackageJsonExportsTrailingSlash1 TestImportCompletionsPackageJsonImportsConditions1 @@ -197,6 +205,7 @@ TestJavaScriptModules14 TestJavascriptModules20 TestJavascriptModules21 TestJavascriptModulesTypeImport +TestJsDocFunctionSignatures3 TestJsDocGenerics1 TestJsdocExtendsTagCompletion TestJsdocImplementsTagCompletion @@ -220,12 +229,16 @@ TestMemberListOnConstructorType TestNoCompletionListOnCommentsInsideObjectLiterals TestNodeModulesImportCompletions1 TestPathCompletionsAllowModuleAugmentationExtensions +TestPathCompletionsAllowTsExtensions TestPathCompletionsPackageJsonExportsBundlerNoNodeCondition TestPathCompletionsPackageJsonExportsCustomConditions TestPathCompletionsPackageJsonExportsWildcard1 TestPathCompletionsPackageJsonExportsWildcard10 TestPathCompletionsPackageJsonExportsWildcard11 TestPathCompletionsPackageJsonExportsWildcard12 +TestPathCompletionsPackageJsonExportsWildcard2 +TestPathCompletionsPackageJsonExportsWildcard3 +TestPathCompletionsPackageJsonExportsWildcard4 TestPathCompletionsPackageJsonExportsWildcard5 TestPathCompletionsPackageJsonExportsWildcard6 TestPathCompletionsPackageJsonExportsWildcard7 @@ -236,6 +249,9 @@ TestPathCompletionsPackageJsonImportsCustomConditions TestPathCompletionsPackageJsonImportsIgnoreMatchingNodeModule2 TestPathCompletionsPackageJsonImportsOnlyFromClosestScope1 TestPathCompletionsPackageJsonImportsSrcNoDistWildcard1 +TestPathCompletionsPackageJsonImportsSrcNoDistWildcard2 +TestPathCompletionsPackageJsonImportsSrcNoDistWildcard3 +TestPathCompletionsPackageJsonImportsSrcNoDistWildcard4 TestPathCompletionsPackageJsonImportsSrcNoDistWildcard5 TestPathCompletionsPackageJsonImportsSrcNoDistWildcard6 TestPathCompletionsPackageJsonImportsSrcNoDistWildcard7 @@ -245,13 +261,21 @@ TestPathCompletionsPackageJsonImportsWildcard1 TestPathCompletionsPackageJsonImportsWildcard10 TestPathCompletionsPackageJsonImportsWildcard11 TestPathCompletionsPackageJsonImportsWildcard12 +TestPathCompletionsPackageJsonImportsWildcard2 +TestPathCompletionsPackageJsonImportsWildcard3 +TestPathCompletionsPackageJsonImportsWildcard4 TestPathCompletionsPackageJsonImportsWildcard5 TestPathCompletionsPackageJsonImportsWildcard6 TestPathCompletionsPackageJsonImportsWildcard7 TestPathCompletionsPackageJsonImportsWildcard8 TestPathCompletionsPackageJsonImportsWildcard9 TestPathCompletionsTypesVersionsLocal +TestPathCompletionsTypesVersionsWildcard1 TestPathCompletionsTypesVersionsWildcard2 +TestPathCompletionsTypesVersionsWildcard3 +TestPathCompletionsTypesVersionsWildcard4 +TestPathCompletionsTypesVersionsWildcard5 +TestPathCompletionsTypesVersionsWildcard6 TestSatisfiesOperatorCompletion TestStringCompletionsImportOrExportSpecifier TestStringCompletionsVsEscaping diff --git a/internal/fourslash/tests/gen/addDeclareToModule_test.go b/internal/fourslash/tests/gen/addDeclareToModule_test.go new file mode 100644 index 0000000000..357ab2e907 --- /dev/null +++ b/internal/fourslash/tests/gen/addDeclareToModule_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestAddDeclareToModule(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/**/module mAmbient { + module m3 { } +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, "declare ") +} diff --git a/internal/fourslash/tests/gen/addSignaturePartial_test.go b/internal/fourslash/tests/gen/addSignaturePartial_test.go new file mode 100644 index 0000000000..9d0a96fe52 --- /dev/null +++ b/internal/fourslash/tests/gen/addSignaturePartial_test.go @@ -0,0 +1,18 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestAddSignaturePartial(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.Insert(t, "interface Number { toFixed") + f.Insert(t, "(") +} diff --git a/internal/fourslash/tests/gen/completionListAfterFunction2_test.go b/internal/fourslash/tests/gen/completionListAfterFunction2_test.go new file mode 100644 index 0000000000..36ca74e7e6 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListAfterFunction2_test.go @@ -0,0 +1,50 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListAfterFunction2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// Outside the function expression +declare var f1: (a: number) => void; /*1*/ + +declare var f1: (b: number, b2: /*2*/) => void;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Excludes: []string{"a"}, + }, + }) + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Excludes: []string{"b"}, + }, + }) + f.Insert(t, "typeof ") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{"b"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListCladule_test.go b/internal/fourslash/tests/gen/completionListCladule_test.go new file mode 100644 index 0000000000..b9e403f7d8 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListCladule_test.go @@ -0,0 +1,55 @@ +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 TestCompletionListCladule(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Foo { + doStuff(): number { return 0; } + static staticMethod() {} +} +module Foo { + export var x: number; +} +Foo/*c1*/; // should get "x", "prototype" +var s: Foo/*c2*/; // no types, in Foo, so shouldnt have anything +var f = new Foo(); +f/*c3*/;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "c1") + f.Insert(t, ".") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{SortText: ptrTo(string(ls.SortTextLocationPriority)), Label: "x"}, &lsproto.CompletionItem{SortText: ptrTo(string(ls.SortTextLocationPriority)), Label: "prototype"}, &lsproto.CompletionItem{SortText: ptrTo(string(ls.SortTextLocalDeclarationPriority)), Label: "staticMethod"}}, + }, + }) + f.GoToMarker(t, "c2") + f.Insert(t, ".") + f.VerifyCompletions(t, nil, nil) + f.GoToMarker(t, "c3") + f.Insert(t, ".") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"doStuff"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListFunctionExpression_test.go b/internal/fourslash/tests/gen/completionListFunctionExpression_test.go new file mode 100644 index 0000000000..cffd415229 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListFunctionExpression_test.go @@ -0,0 +1,40 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListFunctionExpression(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class DataHandler { + dataArray: Uint8Array; + loadData(filename) { + var xmlReq = new XMLHttpRequest(); + xmlReq.open("GET", "/" + filename, true); + xmlReq.responseType = "arraybuffer"; + xmlReq.onload = function(xmlEvent) { + /*local*/ + this./*this*/; + } + } +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "local") + f.InsertLine(t, "") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{"xmlEvent"}, + }, + }) + f.VerifyCompletions(t, "this", nil) +} diff --git a/internal/fourslash/tests/gen/completionListInFunctionDeclaration_test.go b/internal/fourslash/tests/gen/completionListInFunctionDeclaration_test.go new file mode 100644 index 0000000000..f7d4ca6ea0 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListInFunctionDeclaration_test.go @@ -0,0 +1,37 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListInFunctionDeclaration(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var a = 0; +function foo(/**/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", nil) + f.Insert(t, "a") + f.VerifyCompletions(t, nil, nil) + f.Insert(t, " , ") + f.VerifyCompletions(t, nil, nil) + f.Insert(t, "b") + f.VerifyCompletions(t, nil, nil) + f.Insert(t, ":") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: completionGlobalTypes, + }, + }) + f.Insert(t, "number, ") + f.VerifyCompletions(t, nil, nil) +} diff --git a/internal/fourslash/tests/gen/completionListInTypedObjectLiteralsWithPartialPropertyNames_test.go b/internal/fourslash/tests/gen/completionListInTypedObjectLiteralsWithPartialPropertyNames_test.go new file mode 100644 index 0000000000..0e4250a3c5 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListInTypedObjectLiteralsWithPartialPropertyNames_test.go @@ -0,0 +1,65 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListInTypedObjectLiteralsWithPartialPropertyNames(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface MyPoint { + x1: number; + y1: number; +} +var p15: MyPoint = { + /**/ +};` + 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{"x1", "y1"}, + }, + }) + f.Insert(t, "x") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"x1", "y1"}, + }, + }) + f.Insert(t, "1") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"x1", "y1"}, + }, + }) + f.Insert(t, ": null,") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"y1"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListInUnclosedIndexSignature02_test.go b/internal/fourslash/tests/gen/completionListInUnclosedIndexSignature02_test.go new file mode 100644 index 0000000000..d157b3e8e0 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListInUnclosedIndexSignature02_test.go @@ -0,0 +1,40 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListInUnclosedIndexSignature02(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class C { + [foo: /*1*/ +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{"C"}, + Excludes: []string{"foo"}, + }, + }) + f.Insert(t, "typeof ") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{"C", "foo"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completions01_test.go b/internal/fourslash/tests/gen/completions01_test.go new file mode 100644 index 0000000000..5b09b816a4 --- /dev/null +++ b/internal/fourslash/tests/gen/completions01_test.go @@ -0,0 +1,43 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletions01(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var x: string[] = []; +x.forEach(function (y) { y/*1*/ +x.forEach(y => y/*2*/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "1") + f.Insert(t, ".") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{"trim"}, + }, + }) + f.Insert(t, "});") + f.GoToMarker(t, "2") + f.Insert(t, ".") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{"trim"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionsExternalModuleReferenceResolutionOrderInImportDeclaration_test.go b/internal/fourslash/tests/gen/completionsExternalModuleReferenceResolutionOrderInImportDeclaration_test.go new file mode 100644 index 0000000000..670841ba81 --- /dev/null +++ b/internal/fourslash/tests/gen/completionsExternalModuleReferenceResolutionOrderInImportDeclaration_test.go @@ -0,0 +1,38 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionsExternalModuleReferenceResolutionOrderInImportDeclaration(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: externalModuleRefernceResolutionOrderInImportDeclaration_file1.ts +export function foo() { }; +// @Filename: externalModuleRefernceResolutionOrderInImportDeclaration_file2.ts +declare module "externalModuleRefernceResolutionOrderInImportDeclaration_file1" { + export function bar(); +} +// @Filename: externalModuleRefernceResolutionOrderInImportDeclaration_file3.ts +/// +import file1 = require('externalModuleRefernceResolutionOrderInImportDeclaration_file1'); +/*1*/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "1") + f.Insert(t, "file1.") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{"bar"}, + Excludes: []string{"foo"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionsImport_computedSymbolName_test.go b/internal/fourslash/tests/gen/completionsImport_computedSymbolName_test.go new file mode 100644 index 0000000000..195848548e --- /dev/null +++ b/internal/fourslash/tests/gen/completionsImport_computedSymbolName_test.go @@ -0,0 +1,44 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionsImport_computedSymbolName(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /home/src/workspaces/project/tsconfig.json +{ "compilerOptions": { "module": "commonjs" } } +// @Filename: /home/src/workspaces/project/node_modules/@types/ts-node/index.d.ts +export {}; +declare const REGISTER_INSTANCE: unique symbol; +declare global { + namespace NodeJS { + interface Process { + [REGISTER_INSTANCE]?: Service; + } + } +} +// @Filename: /home/src/workspaces/project/node_modules/@types/node/index.d.ts +declare module "process" { + global { + var process: NodeJS.Process; + namespace NodeJS { + interface Process { + argv: string[]; + } + } + } + export = process; +} +// @Filename: /home/src/workspaces/project/index.ts +I/**/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", nil) + f.Insert(t, "N") + f.VerifyCompletions(t, "", nil) +} diff --git a/internal/fourslash/tests/gen/completionsLiteralOverload_test.go b/internal/fourslash/tests/gen/completionsLiteralOverload_test.go new file mode 100644 index 0000000000..840a92f772 --- /dev/null +++ b/internal/fourslash/tests/gen/completionsLiteralOverload_test.go @@ -0,0 +1,51 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionsLiteralOverload(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @Filename: /a.tsx +interface Events { + "": any; + drag: any; + dragenter: any; +} +declare function addListener(type: K, listener: (ev: Events[K]) => any): void; + +declare function ListenerComponent(props: { type: K, onWhatever: (ev: Events[K]) => void }): JSX.Element; + +addListener("/*ts*/"); +(); +// @Filename: /b.js +addListener("/*js*/");` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, []string{"ts", "tsx", "js"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"", "drag", "dragenter"}, + }, + }) + f.Insert(t, "drag") + f.VerifyCompletions(t, []string{"ts", "tsx", "js"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"", "drag", "dragenter"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionsWritingSpreadArgument_test.go b/internal/fourslash/tests/gen/completionsWritingSpreadArgument_test.go new file mode 100644 index 0000000000..d65d5b1d0c --- /dev/null +++ b/internal/fourslash/tests/gen/completionsWritingSpreadArgument_test.go @@ -0,0 +1,33 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionsWritingSpreadArgument(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` + const [] = [Math.min(./*marker*/)] +` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "marker") + f.VerifyCompletions(t, nil, nil) + f.Insert(t, ".") + f.VerifyCompletions(t, nil, nil) + f.Insert(t, ".") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: completionGlobals, + }, + }) +} diff --git a/internal/fourslash/tests/gen/editTemplateConstraint_test.go b/internal/fourslash/tests/gen/editTemplateConstraint_test.go new file mode 100644 index 0000000000..55f88dcc7f --- /dev/null +++ b/internal/fourslash/tests/gen/editTemplateConstraint_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestEditTemplateConstraint(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/** + * @template {/**/ + */ +function f() {}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, "n") + f.Insert(t, "u") +} diff --git a/internal/fourslash/tests/gen/getJavaScriptCompletions18_test.go b/internal/fourslash/tests/gen/getJavaScriptCompletions18_test.go new file mode 100644 index 0000000000..8cc6fd951a --- /dev/null +++ b/internal/fourslash/tests/gen/getJavaScriptCompletions18_test.go @@ -0,0 +1,50 @@ +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 TestGetJavaScriptCompletions18(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowNonTsExtensions: true +// @Filename: file.js +/** + * @param {number} a + * @param {string} b +*/ +exports.foo = function(a, b) { + a/*a*/; + b/*b*/ +};` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "a") + f.Insert(t, ".") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindMethod), Label: "toFixed"}}, + }, + }) + f.GoToMarker(t, "b") + f.Insert(t, ".") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindMethod), Label: "substring"}}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/getJavaScriptCompletions19_test.go b/internal/fourslash/tests/gen/getJavaScriptCompletions19_test.go new file mode 100644 index 0000000000..70d5e80dd8 --- /dev/null +++ b/internal/fourslash/tests/gen/getJavaScriptCompletions19_test.go @@ -0,0 +1,55 @@ +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 TestGetJavaScriptCompletions19(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowNonTsExtensions: true +// @Filename: file.js +function fn() { + if (foo) { + return 0; + } else { + return '0'; + } +} +let x = fn(); +if(typeof x === 'string') { + x/*str*/ +} else { + x/*num*/ +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "str") + f.Insert(t, ".") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindMethod), Label: "substring"}}, + }, + }) + f.GoToMarker(t, "num") + f.Insert(t, ".") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindMethod), Label: "toFixed"}}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/getJavaScriptCompletions22_test.go b/internal/fourslash/tests/gen/getJavaScriptCompletions22_test.go new file mode 100644 index 0000000000..cb9ed4b3b4 --- /dev/null +++ b/internal/fourslash/tests/gen/getJavaScriptCompletions22_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestGetJavaScriptCompletions22(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowNonTsExtensions: true +// @Filename: file.js +const abc = {}; +({./*1*/});` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "1") + f.Insert(t, ".") + f.VerifyCompletions(t, nil, nil) +} diff --git a/internal/fourslash/tests/gen/getJavaScriptQuickInfo8_test.go b/internal/fourslash/tests/gen/getJavaScriptQuickInfo8_test.go new file mode 100644 index 0000000000..d706a07b09 --- /dev/null +++ b/internal/fourslash/tests/gen/getJavaScriptQuickInfo8_test.go @@ -0,0 +1,59 @@ +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 TestGetJavaScriptQuickInfo8(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowNonTsExtensions: true +// @Filename: file.js + let x = { + /** @type {number} */ + get m() { + return undefined; + } + } + x.m/*1*/; + + class Foo { + /** @type {string} */ + get b() { + return undefined; + } + } + var y = new Foo(); + y.b/*2*/;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "1") + f.Insert(t, ".") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindMethod), Label: "toFixed"}}, + }, + }) + f.Backspace(t, 1) + f.GoToMarker(t, "2") + f.Insert(t, ".") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindMethod), Label: "substring"}}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/incrementalParsingInsertIntoMethod1_test.go b/internal/fourslash/tests/gen/incrementalParsingInsertIntoMethod1_test.go new file mode 100644 index 0000000000..fc320bbc0b --- /dev/null +++ b/internal/fourslash/tests/gen/incrementalParsingInsertIntoMethod1_test.go @@ -0,0 +1,24 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestIncrementalParsingInsertIntoMethod1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class C { + public foo1() { } + public foo2() { + return 1/*1*/; + } + public foo3() { } +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "1") + f.Insert(t, " + 1") +} diff --git a/internal/fourslash/tests/gen/jsDocFunctionSignatures3_test.go b/internal/fourslash/tests/gen/jsDocFunctionSignatures3_test.go new file mode 100644 index 0000000000..77931362be --- /dev/null +++ b/internal/fourslash/tests/gen/jsDocFunctionSignatures3_test.go @@ -0,0 +1,61 @@ +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 TestJsDocFunctionSignatures3(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowNonTsExtensions: true +// @Filename: Foo.js + var someObject = { + /** + * @param {string} param1 Some string param. + * @param {number} parm2 Some number param. + */ + someMethod: function(param1, param2) { + console.log(param1/*1*/); + return false; + }, + /** + * @param {number} p1 Some number param. + */ + otherMethod(p1) { + p1/*2*/ + } + + };` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "1") + f.Insert(t, ".") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindMethod), Label: "substring"}}, + }, + }) + f.Backspace(t, 1) + f.GoToMarker(t, "2") + f.Insert(t, ".") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindMethod), Label: "toFixed"}}, + }, + }) + f.Backspace(t, 1) +} diff --git a/internal/fourslash/tests/gen/pathCompletionsAllowTsExtensions_test.go b/internal/fourslash/tests/gen/pathCompletionsAllowTsExtensions_test.go new file mode 100644 index 0000000000..6bc6a1a7f5 --- /dev/null +++ b/internal/fourslash/tests/gen/pathCompletionsAllowTsExtensions_test.go @@ -0,0 +1,53 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestPathCompletionsAllowTsExtensions(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @moduleResolution: bundler +// @allowImportingTsExtensions: true +// @noEmit: true +// @Filename: /project/foo.ts +export const foo = 0; +// @Filename: /project/main.ts +import {} from ".//**/"` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"foo"}, + }, + }) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"foo.ts"}, + }, + }) + f.Insert(t, "foo.ts\"\nimport {} from \"./") + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"foo.ts"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/pathCompletionsPackageJsonExportsWildcard2_test.go b/internal/fourslash/tests/gen/pathCompletionsPackageJsonExportsWildcard2_test.go new file mode 100644 index 0000000000..94305a2708 --- /dev/null +++ b/internal/fourslash/tests/gen/pathCompletionsPackageJsonExportsWildcard2_test.go @@ -0,0 +1,65 @@ +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 TestPathCompletionsPackageJsonExportsWildcard2(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @module: node18 +// @Filename: /node_modules/salesforce-pageobjects/package.json +{ + "name": "salesforce-pageobjects", + "version": "1.0.0", + "exports": { + "./*": { + "types": "./dist/*.d.ts", + "import": "./dist/*.mjs", + "default": "./dist/*.js" + } + } +} +// @Filename: /node_modules/salesforce-pageobjects/dist/action/pageObjects/actionRenderer.d.ts +export const actionRenderer = 0; +// @Filename: /index.mts +import { } from "salesforce-pageobjects//**/";` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFolder), Label: "action"}}, + }, + }) + f.Insert(t, "action/") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFolder), Label: "pageObjects"}}, + }, + }) + f.Insert(t, "pageObjects/") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "actionRenderer"}}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/pathCompletionsPackageJsonExportsWildcard3_test.go b/internal/fourslash/tests/gen/pathCompletionsPackageJsonExportsWildcard3_test.go new file mode 100644 index 0000000000..d6abc92f8c --- /dev/null +++ b/internal/fourslash/tests/gen/pathCompletionsPackageJsonExportsWildcard3_test.go @@ -0,0 +1,57 @@ +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 TestPathCompletionsPackageJsonExportsWildcard3(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @module: node18 +// @Filename: /node_modules/foo/package.json +{ + "types": "index.d.ts", + "exports": { + "./component-*": { + "types@>=4.3.5": "types/components/*.d.ts" + } + } +} +// @Filename: /node_modules/foo/nope.d.ts +export const nope = 0; +// @Filename: /node_modules/foo/types/components/index.d.ts +export const index = 0; +// @Filename: /node_modules/foo/types/components/blah.d.ts +export const blah = 0; +// @Filename: /node_modules/foo/types/components/subfolder/one.d.ts +export const one = 0; +// @Filename: /a.ts +import { } from "foo//**/";` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "component-blah"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "component-index"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFolder), Label: "component-subfolder"}}, + }, + }) + f.Insert(t, "component-subfolder/") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "one"}}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/pathCompletionsPackageJsonExportsWildcard4_test.go b/internal/fourslash/tests/gen/pathCompletionsPackageJsonExportsWildcard4_test.go new file mode 100644 index 0000000000..132733ebe1 --- /dev/null +++ b/internal/fourslash/tests/gen/pathCompletionsPackageJsonExportsWildcard4_test.go @@ -0,0 +1,71 @@ +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 TestPathCompletionsPackageJsonExportsWildcard4(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @module: node18 +// @Filename: /node_modules/foo/package.json +{ + "types": "index.d.ts", + "exports": { + "./*": "dist/*", + "./foo/*": "dist/*", + "./bar/*": "dist/*", + "./exact-match": "dist/index.d.ts" + } +} +// @Filename: /node_modules/foo/nope.d.ts +export const nope = 0; +// @Filename: /node_modules/foo/dist/index.d.ts +export const index = 0; +// @Filename: /node_modules/foo/dist/blah.d.ts +export const blah = 0; +// @Filename: /node_modules/foo/dist/foo/onlyInFooFolder.d.ts +export const foo = 0; +// @Filename: /node_modules/foo/dist/subfolder/one.d.ts +export const one = 0; +// @Filename: /a.mts +import { } from "foo//**/";` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "blah.js"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "index.js"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFolder), Label: "foo"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFolder), Label: "subfolder"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFolder), Label: "bar"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "exact-match"}}, + }, + }) + f.Insert(t, "foo/") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "blah.js"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "index.js"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFolder), Label: "foo"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFolder), Label: "subfolder"}}, + }, + }) + f.Insert(t, "foo/") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "onlyInFooFolder.js"}}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/pathCompletionsPackageJsonImportsSrcNoDistWildcard2_test.go b/internal/fourslash/tests/gen/pathCompletionsPackageJsonImportsSrcNoDistWildcard2_test.go new file mode 100644 index 0000000000..7b07045978 --- /dev/null +++ b/internal/fourslash/tests/gen/pathCompletionsPackageJsonImportsSrcNoDistWildcard2_test.go @@ -0,0 +1,72 @@ +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 TestPathCompletionsPackageJsonImportsSrcNoDistWildcard2(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /home/src/workspaces/project/tsconfig.json +{ + "compilerOptions": { + "module": "nodenext", + "rootDir": "src", + "outDir": "dist" + } +} +// @Filename: /home/src/workspaces/project/package.json +{ + "name": "salesforce-pageobjects", + "version": "1.0.0", + "imports": { + "#*": { + "types": "./dist/*.d.ts", + "import": "./dist/*.mjs", + "default": "./dist/*.js" + } + } +} +// @Filename: /home/src/workspaces/project/src/action/pageObjects/actionRenderer.ts +export const actionRenderer = 0; +// @Filename: /home/src/workspaces/project/src/index.mts +import { } from "/**/";` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFolder), Label: "#action"}}, + }, + }) + f.Insert(t, "#action/") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFolder), Label: "pageObjects"}}, + }, + }) + f.Insert(t, "pageObjects/") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "actionRenderer"}}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/pathCompletionsPackageJsonImportsSrcNoDistWildcard3_test.go b/internal/fourslash/tests/gen/pathCompletionsPackageJsonImportsSrcNoDistWildcard3_test.go new file mode 100644 index 0000000000..c4326e9826 --- /dev/null +++ b/internal/fourslash/tests/gen/pathCompletionsPackageJsonImportsSrcNoDistWildcard3_test.go @@ -0,0 +1,65 @@ +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 TestPathCompletionsPackageJsonImportsSrcNoDistWildcard3(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /home/src/workspaces/project/tsconfig.json +{ + "compilerOptions": { + "module": "nodenext", + "rootDir": "src", + "outDir": "dist", + "declarationDir": "types" + } +} +// @Filename: /home/src/workspaces/project/package.json +{ + "types": "index.d.ts", + "imports": { + "#component-*": { + "types@>=4.3.5": "types/components/*.d.ts" + } + } +} +// @Filename: /home/src/workspaces/project/nope.ts +export const nope = 0; +// @Filename: /home/src/workspaces/project/src/components/index.ts +export const index = 0; +// @Filename: /home/src/workspaces/project/src/components/blah.ts +export const blah = 0; +// @Filename: /home/src/workspaces/project/src/components/subfolder/one.ts +export const one = 0; +// @Filename: /home/src/workspaces/project/src/a.ts +import { } from "/**/";` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "#component-blah"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "#component-index"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFolder), Label: "#component-subfolder"}}, + }, + }) + f.Insert(t, "#component-subfolder/") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "one"}}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/pathCompletionsPackageJsonImportsSrcNoDistWildcard4_test.go b/internal/fourslash/tests/gen/pathCompletionsPackageJsonImportsSrcNoDistWildcard4_test.go new file mode 100644 index 0000000000..82e053bad9 --- /dev/null +++ b/internal/fourslash/tests/gen/pathCompletionsPackageJsonImportsSrcNoDistWildcard4_test.go @@ -0,0 +1,78 @@ +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 TestPathCompletionsPackageJsonImportsSrcNoDistWildcard4(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /home/src/workspaces/project/tsconfig.json +{ + "compilerOptions": { + "module": "nodenext", + "rootDir": "src", + "outDir": "dist" + } +} +// @Filename: /home/src/workspaces/project/package.json +{ + "types": "index.d.ts", + "imports": { + "#*": "dist/*", + "#foo/*": "dist/*", + "#bar/*": "dist/*", + "#exact-match": "dist/index.d.ts" + } +} +// @Filename: /home/src/workspaces/project/nope.ts +export const nope = 0; +// @Filename: /home/src/workspaces/project/src/index.ts +export const index = 0; +// @Filename: /home/src/workspaces/project/src/blah.ts +export const blah = 0; +// @Filename: /home/src/workspaces/project/src/foo/onlyInFooFolder.ts +export const foo = 0; +// @Filename: /home/src/workspaces/project/src/subfolder/one.ts +export const one = 0; +// @Filename: /home/src/workspaces/project/src/a.mts +import { } from "/**/";` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "#a.mjs"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "#blah.js"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "#index.js"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFolder), Label: "#foo"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFolder), Label: "#subfolder"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFolder), Label: "#bar"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "#exact-match"}}, + }, + }) + f.Insert(t, "#foo/") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "a.mjs"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "blah.js"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "index.js"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFolder), Label: "foo"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFolder), Label: "subfolder"}}, + }, + }) + f.Insert(t, "foo/") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "onlyInFooFolder.js"}}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/pathCompletionsPackageJsonImportsWildcard2_test.go b/internal/fourslash/tests/gen/pathCompletionsPackageJsonImportsWildcard2_test.go new file mode 100644 index 0000000000..628ec8c1ab --- /dev/null +++ b/internal/fourslash/tests/gen/pathCompletionsPackageJsonImportsWildcard2_test.go @@ -0,0 +1,65 @@ +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 TestPathCompletionsPackageJsonImportsWildcard2(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @module: node18 +// @Filename: /package.json +{ + "name": "salesforce-pageobjects", + "version": "1.0.0", + "imports": { + "#*": { + "types": "./dist/*.d.ts", + "import": "./dist/*.mjs", + "default": "./dist/*.js" + } + } +} +// @Filename: /dist/action/pageObjects/actionRenderer.d.ts +export const actionRenderer = 0; +// @Filename: /index.mts +import { } from "/**/";` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFolder), Label: "#action"}}, + }, + }) + f.Insert(t, "#action/") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFolder), Label: "pageObjects"}}, + }, + }) + f.Insert(t, "pageObjects/") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "actionRenderer"}}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/pathCompletionsPackageJsonImportsWildcard3_test.go b/internal/fourslash/tests/gen/pathCompletionsPackageJsonImportsWildcard3_test.go new file mode 100644 index 0000000000..97eb0b800e --- /dev/null +++ b/internal/fourslash/tests/gen/pathCompletionsPackageJsonImportsWildcard3_test.go @@ -0,0 +1,57 @@ +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 TestPathCompletionsPackageJsonImportsWildcard3(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @module: node18 +// @Filename: /package.json +{ + "types": "index.d.ts", + "imports": { + "#component-*": { + "types@>=4.3.5": "types/components/*.d.ts" + } + } +} +// @Filename: /nope.d.ts +export const nope = 0; +// @Filename: /types/components/index.d.ts +export const index = 0; +// @Filename: /types/components/blah.d.ts +export const blah = 0; +// @Filename: /types/components/subfolder/one.d.ts +export const one = 0; +// @Filename: /a.ts +import { } from "/**/";` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "#component-blah"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "#component-index"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFolder), Label: "#component-subfolder"}}, + }, + }) + f.Insert(t, "#component-subfolder/") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "one"}}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/pathCompletionsPackageJsonImportsWildcard4_test.go b/internal/fourslash/tests/gen/pathCompletionsPackageJsonImportsWildcard4_test.go new file mode 100644 index 0000000000..355eece6fa --- /dev/null +++ b/internal/fourslash/tests/gen/pathCompletionsPackageJsonImportsWildcard4_test.go @@ -0,0 +1,71 @@ +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 TestPathCompletionsPackageJsonImportsWildcard4(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @module: node18 +// @Filename: /package.json +{ + "types": "index.d.ts", + "imports": { + "#*": "dist/*", + "#foo/*": "dist/*", + "#bar/*": "dist/*", + "#exact-match": "dist/index.d.ts" + } +} +// @Filename: /nope.d.ts +export const nope = 0; +// @Filename: /dist/index.d.ts +export const index = 0; +// @Filename: /dist/blah.d.ts +export const blah = 0; +// @Filename: /dist/foo/onlyInFooFolder.d.ts +export const foo = 0; +// @Filename: /dist/subfolder/one.d.ts +export const one = 0; +// @Filename: /a.mts +import { } from "/**/";` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "#blah.js"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "#index.js"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFolder), Label: "#foo"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFolder), Label: "#subfolder"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFolder), Label: "#bar"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "#exact-match"}}, + }, + }) + f.Insert(t, "#foo/") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "blah.js"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "index.js"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFolder), Label: "foo"}, &lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFolder), Label: "subfolder"}}, + }, + }) + f.Insert(t, "foo/") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindFile), Label: "onlyInFooFolder.js"}}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/pathCompletionsTypesVersionsWildcard1_test.go b/internal/fourslash/tests/gen/pathCompletionsTypesVersionsWildcard1_test.go new file mode 100644 index 0000000000..012e56477e --- /dev/null +++ b/internal/fourslash/tests/gen/pathCompletionsTypesVersionsWildcard1_test.go @@ -0,0 +1,56 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestPathCompletionsTypesVersionsWildcard1(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @module: commonjs +// @Filename: /node_modules/foo/package.json +{ + "types": "index.d.ts", + "typesVersions": { + "*": { + "*": ["dist/*"] + } + } +} +// @Filename: /node_modules/foo/nope.d.ts +export const nope = 0; +// @Filename: /node_modules/foo/dist/index.d.ts +export const index = 0; +// @Filename: /node_modules/foo/dist/blah.d.ts +export const blah = 0; +// @Filename: /node_modules/foo/dist/subfolder/one.d.ts +export const one = 0; +// @Filename: /a.ts +import { } from "foo//**/";` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"blah", "index", "subfolder"}, + }, + }) + f.Insert(t, "subfolder/") + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"one"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/pathCompletionsTypesVersionsWildcard3_test.go b/internal/fourslash/tests/gen/pathCompletionsTypesVersionsWildcard3_test.go new file mode 100644 index 0000000000..163c78d807 --- /dev/null +++ b/internal/fourslash/tests/gen/pathCompletionsTypesVersionsWildcard3_test.go @@ -0,0 +1,67 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestPathCompletionsTypesVersionsWildcard3(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @module: commonjs +// @Filename: /node_modules/foo/package.json +{ + "types": "index.d.ts", + "typesVersions": { + ">=4.3.5": { + "browser/*": ["dist/*"] + } + } +} +// @Filename: /node_modules/foo/nope.d.ts +export const nope = 0; +// @Filename: /node_modules/foo/dist/index.d.ts +export const index = 0; +// @Filename: /node_modules/foo/dist/blah.d.ts +export const blah = 0; +// @Filename: /node_modules/foo/dist/subfolder/one.d.ts +export const one = 0; +// @Filename: /a.ts +import { } from "foo//**/";` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"browser", "nope", "dist"}, + }, + }) + f.Insert(t, "browser/") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"blah", "index", "subfolder"}, + }, + }) + f.Insert(t, "subfolder/") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"one"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/pathCompletionsTypesVersionsWildcard4_test.go b/internal/fourslash/tests/gen/pathCompletionsTypesVersionsWildcard4_test.go new file mode 100644 index 0000000000..31d57ded01 --- /dev/null +++ b/internal/fourslash/tests/gen/pathCompletionsTypesVersionsWildcard4_test.go @@ -0,0 +1,56 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestPathCompletionsTypesVersionsWildcard4(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @module: commonjs +// @Filename: /node_modules/foo/package.json +{ + "types": "index.d.ts", + "typesVersions": { + ">=4.3.5": { + "component-*": ["cjs/components/*"] + } + } +} +// @Filename: /node_modules/foo/nope.d.ts +export const nope = 0; +// @Filename: /node_modules/foo/cjs/components/index.d.ts +export const index = 0; +// @Filename: /node_modules/foo/cjs/components/blah.d.ts +export const blah = 0; +// @Filename: /node_modules/foo/cjs/components/subfolder/one.d.ts +export const one = 0; +// @Filename: /a.ts +import { } from "foo//**/";` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"component-blah", "component-index", "component-subfolder", "nope", "cjs"}, + }, + }) + f.Insert(t, "component-subfolder/") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"one"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/pathCompletionsTypesVersionsWildcard5_test.go b/internal/fourslash/tests/gen/pathCompletionsTypesVersionsWildcard5_test.go new file mode 100644 index 0000000000..32bb4fdbdd --- /dev/null +++ b/internal/fourslash/tests/gen/pathCompletionsTypesVersionsWildcard5_test.go @@ -0,0 +1,72 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestPathCompletionsTypesVersionsWildcard5(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @module: commonjs +// @Filename: /node_modules/foo/package.json +{ + "types": "index.d.ts", + "typesVersions": { + "*": { + "*": ["dist/*"], + "foo/*": ["dist/*"], + "bar/*": ["dist/*"], + "exact-match": ["dist/index.d.ts"] + } + } +} +// @Filename: /node_modules/foo/nope.d.ts +export const nope = 0; +// @Filename: /node_modules/foo/dist/index.d.ts +export const index = 0; +// @Filename: /node_modules/foo/dist/blah.d.ts +export const blah = 0; +// @Filename: /node_modules/foo/dist/foo/onlyInFooFolder.d.ts +export const foo = 0; +// @Filename: /node_modules/foo/dist/subfolder/one.d.ts +export const one = 0; +// @Filename: /a.ts +import { } from "foo//**/";` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"blah", "index", "foo", "subfolder", "bar", "exact-match"}, + }, + }) + f.Insert(t, "foo/") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"blah", "index", "foo", "subfolder"}, + }, + }) + f.Insert(t, "foo/") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"onlyInFooFolder"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/pathCompletionsTypesVersionsWildcard6_test.go b/internal/fourslash/tests/gen/pathCompletionsTypesVersionsWildcard6_test.go new file mode 100644 index 0000000000..b0a2aab3fd --- /dev/null +++ b/internal/fourslash/tests/gen/pathCompletionsTypesVersionsWildcard6_test.go @@ -0,0 +1,72 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestPathCompletionsTypesVersionsWildcard6(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @module: commonjs +// @Filename: /node_modules/foo/package.json +{ + "types": "index.d.ts", + "typesVersions": { + "*": { + "bar/*": ["dist/*"], + "exact-match": ["dist/index.d.ts"], + "foo/*": ["dist/*"], + "*": ["dist/*"] + } + } +} +// @Filename: /node_modules/foo/nope.d.ts +export const nope = 0; +// @Filename: /node_modules/foo/dist/index.d.ts +export const index = 0; +// @Filename: /node_modules/foo/dist/blah.d.ts +export const blah = 0; +// @Filename: /node_modules/foo/dist/foo/onlyInFooFolder.d.ts +export const foo = 0; +// @Filename: /node_modules/foo/dist/subfolder/one.d.ts +export const one = 0; +// @Filename: /a.ts +import { } from "foo//**/";` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"bar", "exact-match", "foo", "blah", "index", "subfolder"}, + }, + }) + f.Insert(t, "foo/") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"blah", "index", "foo", "subfolder"}, + }, + }) + f.Insert(t, "foo/") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"onlyInFooFolder"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/propertyDuplicateIdentifierError_test.go b/internal/fourslash/tests/gen/propertyDuplicateIdentifierError_test.go new file mode 100644 index 0000000000..4e4096028d --- /dev/null +++ b/internal/fourslash/tests/gen/propertyDuplicateIdentifierError_test.go @@ -0,0 +1,21 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestPropertyDuplicateIdentifierError(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `export class C { + x: number; + get x(): number { return 1; } +}/*1*/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "1") + f.Insert(t, "/n") +} diff --git a/internal/fourslash/tests/gen/regexErrorRecovery_test.go b/internal/fourslash/tests/gen/regexErrorRecovery_test.go new file mode 100644 index 0000000000..fddd78c382 --- /dev/null +++ b/internal/fourslash/tests/gen/regexErrorRecovery_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestRegexErrorRecovery(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` // test code +//var x = //**/a/;/*1*/ +//x.exec("bab"); + Bug 579071: Parser no longer detects a Regex when an open bracket is inserted +verify.quickInfoIs("RegExp"); +verify.not.errorExistsAfterMarker("1");` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.Insert(t, "(") +} diff --git a/internal/fourslash/tests/gen/superCallError0_test.go b/internal/fourslash/tests/gen/superCallError0_test.go new file mode 100644 index 0000000000..90fba8acdb --- /dev/null +++ b/internal/fourslash/tests/gen/superCallError0_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestSuperCallError0(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class T5{ + constructor(public bar: T) { } +} +class T6 extends T5{ + constructor() { + super(); + } +}/*1*/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "1") + f.Insert(t, "/n") +} diff --git a/internal/fourslash/tests/gen/syntaxErrorAfterImport1_test.go b/internal/fourslash/tests/gen/syntaxErrorAfterImport1_test.go new file mode 100644 index 0000000000..2479e47fb0 --- /dev/null +++ b/internal/fourslash/tests/gen/syntaxErrorAfterImport1_test.go @@ -0,0 +1,27 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestSyntaxErrorAfterImport1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `declare module "extmod" { + module IntMod { + class Customer { + constructor(name: string); + } + } +} +import ext = require('extmod'); +import int = ext.IntMod; +var x = new int/*0*/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "0") + f.Insert(t, ".") +} diff --git a/internal/fourslash/tests/gen/typeCheckAfterAddingGenericParameter_test.go b/internal/fourslash/tests/gen/typeCheckAfterAddingGenericParameter_test.go new file mode 100644 index 0000000000..e8d2704b0d --- /dev/null +++ b/internal/fourslash/tests/gen/typeCheckAfterAddingGenericParameter_test.go @@ -0,0 +1,31 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestTypeCheckAfterAddingGenericParameter(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function f() { } +function f2(b: X): X { return null; } +class C { + public f() {} +f2(b): X { return null; } +} + +interface I { + f(); + f2(/*addParam*/a: X): X; +} +` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "addParam") + f.Insert(t, ", X") + f.GoToMarker(t, "addTypeParam") + f.Insert(t, ", X") +} diff --git a/internal/fourslash/tests/gen/updateSourceFile_jsdocSignature_test.go b/internal/fourslash/tests/gen/updateSourceFile_jsdocSignature_test.go new file mode 100644 index 0000000000..b07019ee4c --- /dev/null +++ b/internal/fourslash/tests/gen/updateSourceFile_jsdocSignature_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestUpdateSourceFile_jsdocSignature(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/** + * @callback Cb + * @return {/**/} + */ +let x;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, "number") +} From faa84a900818cc6273e54f89dd098360c59e5862 Mon Sep 17 00:00:00 2001 From: Gabriela Araujo Britto Date: Fri, 27 Jun 2025 16:25:19 -0700 Subject: [PATCH 6/6] fix failing tests after merge --- internal/fourslash/_scripts/failingTests.txt | 1 - .../tests/gen/completionListInObjectBindingPattern16_test.go | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/fourslash/_scripts/failingTests.txt b/internal/fourslash/_scripts/failingTests.txt index 87be11ba0f..6f2433c745 100644 --- a/internal/fourslash/_scripts/failingTests.txt +++ b/internal/fourslash/_scripts/failingTests.txt @@ -80,7 +80,6 @@ TestCompletionListInFunctionDeclaration TestCompletionListInImportClause01 TestCompletionListInImportClause05 TestCompletionListInImportClause06 -TestCompletionListInObjectBindingPattern16 TestCompletionListInScope TestCompletionListInTemplateLiteralParts1 TestCompletionListInUnclosedCommaExpression01 diff --git a/internal/fourslash/tests/gen/completionListInObjectBindingPattern16_test.go b/internal/fourslash/tests/gen/completionListInObjectBindingPattern16_test.go index fdae840318..764b78211e 100644 --- a/internal/fourslash/tests/gen/completionListInObjectBindingPattern16_test.go +++ b/internal/fourslash/tests/gen/completionListInObjectBindingPattern16_test.go @@ -9,7 +9,7 @@ import ( func TestCompletionListInObjectBindingPattern16(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `// @allowJs: true // @checkJs: true