-
Notifications
You must be signed in to change notification settings - Fork 808
Port non-baseline diagnostics tests #2079
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -556,6 +556,16 @@ func (f *FourslashTest) Ranges() []*RangeMarker { | |
| return f.testData.Ranges | ||
| } | ||
|
|
||
| func (f *FourslashTest) getRangesInFile(fileName string) []*RangeMarker { | ||
| var rangesInFile []*RangeMarker | ||
| for _, rangeMarker := range f.testData.Ranges { | ||
| if rangeMarker.FileName() == fileName { | ||
| rangesInFile = append(rangesInFile, rangeMarker) | ||
| } | ||
| } | ||
| return rangesInFile | ||
| } | ||
|
|
||
| func (f *FourslashTest) ensureActiveFile(t *testing.T, filename string) { | ||
| if f.activeFilename != filename { | ||
| f.openFile(t, filename) | ||
|
|
@@ -913,8 +923,9 @@ func ignorePaths(paths ...string) cmp.Option { | |
| } | ||
|
|
||
| var ( | ||
| completionIgnoreOpts = ignorePaths(".Kind", ".SortText", ".FilterText", ".Data") | ||
| autoImportIgnoreOpts = ignorePaths(".Kind", ".SortText", ".FilterText", ".Data", ".LabelDetails", ".Detail", ".AdditionalTextEdits") | ||
| completionIgnoreOpts = ignorePaths(".Kind", ".SortText", ".FilterText", ".Data") | ||
| autoImportIgnoreOpts = ignorePaths(".Kind", ".SortText", ".FilterText", ".Data", ".LabelDetails", ".Detail", ".AdditionalTextEdits") | ||
| diagnosticsIgnoreOpts = ignorePaths(".Severity", ".Source", ".RelatedInformation") | ||
| ) | ||
|
|
||
| func (f *FourslashTest) verifyCompletionItem(t *testing.T, prefix string, actual *lsproto.CompletionItem, expected *lsproto.CompletionItem) { | ||
|
|
@@ -1815,7 +1826,12 @@ func (f *FourslashTest) ReplaceLine(t *testing.T, lineIndex int, text string) { | |
| 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 | ||
| var end core.TextPos | ||
| if lineIndex+1 >= len(script.lineMap.LineStarts) { | ||
| end = core.TextPos(len(script.content)) | ||
| } else { | ||
| end = script.lineMap.LineStarts[lineIndex+1] - 1 | ||
| } | ||
| f.selectRange(t, core.NewTextRange(int(start), int(end))) | ||
| } | ||
|
|
||
|
|
@@ -2474,6 +2490,60 @@ func (f *FourslashTest) VerifyBaselineInlayHints( | |
| f.addResultToBaseline(t, "Inlay Hints", strings.Join(annotations, "\n\n")) | ||
| } | ||
|
|
||
| func (f *FourslashTest) VerifyDiagnostics(t *testing.T, expected []*lsproto.Diagnostic) { | ||
| f.verifyDiagnostics(t, expected, func(d *lsproto.Diagnostic) bool { return true }) | ||
| } | ||
|
|
||
| // Similar to `VerifyDiagnostics`, but excludes suggestion diagnostics returned from server. | ||
| func (f *FourslashTest) VerifyNonSuggestionDiagnostics(t *testing.T, expected []*lsproto.Diagnostic) { | ||
| f.verifyDiagnostics(t, expected, func(d *lsproto.Diagnostic) bool { return !isSuggestionDiagnostic(d) }) | ||
| } | ||
|
|
||
| // Similar to `VerifyDiagnostics`, but includes only suggestion diagnostics returned from server. | ||
| func (f *FourslashTest) VerifySuggestionDiagnostics(t *testing.T, expected []*lsproto.Diagnostic) { | ||
| f.verifyDiagnostics(t, expected, isSuggestionDiagnostic) | ||
| } | ||
|
|
||
| func (f *FourslashTest) verifyDiagnostics(t *testing.T, expected []*lsproto.Diagnostic, filterDiagnostics func(*lsproto.Diagnostic) bool) { | ||
| params := &lsproto.DocumentDiagnosticParams{ | ||
| TextDocument: lsproto.TextDocumentIdentifier{ | ||
| Uri: lsconv.FileNameToDocumentURI(f.activeFilename), | ||
| }, | ||
| } | ||
| resMsg, result, resultOk := sendRequest(t, f, lsproto.TextDocumentDiagnosticInfo, params) | ||
| if resMsg == nil { | ||
| t.Fatal("Nil response received for diagnostics request") | ||
| } | ||
| if !resultOk { | ||
| t.Fatalf("Unexpected response type for diagnostics request: %T", resMsg.AsResponse().Result) | ||
| } | ||
|
|
||
| var actualDiagnostics []*lsproto.Diagnostic | ||
| if result.FullDocumentDiagnosticReport != nil { | ||
| actualDiagnostics = append(actualDiagnostics, result.FullDocumentDiagnosticReport.Items...) | ||
| } | ||
| actualDiagnostics = core.Filter(actualDiagnostics, filterDiagnostics) | ||
| emptyRange := lsproto.Range{} | ||
| for _, diag := range expected { | ||
| if diag.Range == emptyRange { | ||
| rangesInFile := f.getRangesInFile(f.activeFilename) | ||
| if len(rangesInFile) == 0 { | ||
| t.Fatalf("No ranges found in file %s to assign to diagnostic with empty range", f.activeFilename) | ||
| } | ||
| diag.Range = rangesInFile[0].LSRange | ||
| } | ||
| } | ||
| if len(actualDiagnostics) == 0 { | ||
| actualDiagnostics = nil | ||
| } | ||
| assertDeepEqual(t, actualDiagnostics, expected, "Diagnostics do not match expected", diagnosticsIgnoreOpts) | ||
| } | ||
|
|
||
| func isSuggestionDiagnostic(diag *lsproto.Diagnostic) bool { | ||
| return diag.Tags != nil && len(*diag.Tags) > 0 || | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestions don't necessarily have to have tags; e.g. if we were to do the "convert to ESM" fix, that would just be a hint, no tags. The tags just apply a visual change like strikethrough or greying out.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an heuristic, as I think we don't have a consistent way of signaling a diagnostic is a suggestion, right? e.g. the unreachable code diagnostic has a tag, but its severity is
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is so long as allowUnreachableCode is true; if it's undefined then it's |
||
| (diag.Severity != nil && *diag.Severity == lsproto.DiagnosticSeverityHint) | ||
| } | ||
|
|
||
| func isLibFile(fileName string) bool { | ||
| baseName := tspath.GetBaseFileName(fileName) | ||
| if strings.HasPrefix(baseName, "lib.") && strings.HasSuffix(baseName, ".d.ts") { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package fourslash_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/microsoft/typescript-go/internal/fourslash" | ||
| "github.com/microsoft/typescript-go/internal/testutil" | ||
| ) | ||
|
|
||
| func TestAnnotateWithTypeFromJSDoc2(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| defer testutil.RecoverAndFail(t, "Panic on fourslash test") | ||
| const content = `// @Filename: test123.ts | ||
| /** @type {number} */ | ||
| var [|x|]: string;` | ||
| f := fourslash.NewFourslash(t, nil /*capabilities*/, content) | ||
| f.VerifySuggestionDiagnostics(t, nil) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package fourslash_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/microsoft/typescript-go/internal/fourslash" | ||
| . "github.com/microsoft/typescript-go/internal/fourslash/tests/util" | ||
| "github.com/microsoft/typescript-go/internal/testutil" | ||
| ) | ||
|
|
||
| func TestAutoImportModuleNone1(t *testing.T) { | ||
| t.Parallel() | ||
| t.Skip() | ||
| defer testutil.RecoverAndFail(t, "Panic on fourslash test") | ||
| const content = `// @module: none | ||
| // @moduleResolution: bundler | ||
| // @target: es5 | ||
| // @Filename: /node_modules/dep/index.d.ts | ||
| export const x: number; | ||
| // @Filename: /index.ts | ||
| x/**/` | ||
| f := fourslash.NewFourslash(t, nil /*capabilities*/, content) | ||
| f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ | ||
| IsIncomplete: false, | ||
| ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ | ||
| CommitCharacters: &DefaultCommitCharacters, | ||
| EditRange: Ignored, | ||
| }, | ||
| Items: &fourslash.CompletionsExpectedItems{ | ||
| Excludes: []string{ | ||
| "x", | ||
| }, | ||
| }, | ||
| }) | ||
| f.ReplaceLine(t, 0, "import { x } from 'dep'; x;") | ||
| f.VerifyNonSuggestionDiagnostics(t, nil) | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.