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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/peter-evans/patience v0.3.0
github.com/zeebo/xxh3 v1.1.0
golang.org/x/sync v0.20.0
golang.org/x/sys v0.45.0
golang.org/x/sys v0.43.0
golang.org/x/text v0.36.0
gotest.tools/v3 v3.5.2
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ github.com/zeebo/xxh3 v1.1.0 h1:s7DLGDK45Dyfg7++yxI0khrfwq9661w9EN78eP/UZVs=
github.com/zeebo/xxh3 v1.1.0/go.mod h1:IisAie1LELR4xhVinxWS5+zf1lA4p0MW4T+w+W07F5s=
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY=
golang.org/x/sys v0.45.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/sys v0.43.0 h1:Rlag2XtaFTxp19wS8MXlJwTvoh8ArU6ezoyFsMyCTNI=
golang.org/x/sys v0.43.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/text v0.36.0 h1:JfKh3XmcRPqZPKevfXVpI1wXPTqbkE5f7JA92a55Yxg=
golang.org/x/text v0.36.0/go.mod h1:NIdBknypM8iqVmPiuco0Dh6P5Jcdk8lJL0CUebqK164=
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
Expand Down
2 changes: 1 addition & 1 deletion microsoft/typescript-go
Submodule typescript-go updated 60 files
+26 −23 _extension/src/commands.ts
+3 −1 _extension/src/extension.ts
+24 −5 _extension/src/util.ts
+4 −3 internal/checker/checker.go
+2 −1 internal/fourslash/baselineutil.go
+80 −0 internal/fourslash/fourslash.go
+23 −0 internal/fourslash/tests/constructorFindAllReferences1VS_test.go
+36 −0 internal/fourslash/tests/decoratorOnPrivateMethod_test.go
+24 −0 internal/fourslash/tests/findAllRefsForDefaultExportVS_test.go
+25 −0 internal/fourslash/tests/findAllRefsInheritedProperties1VS_test.go
+25 −0 internal/fourslash/tests/findReferencesAcrossMultipleProjectsVS_test.go
+29 −0 internal/fourslash/tests/tsxFindAllReferences1VS_test.go
+28 −0 internal/ls/crossproject.go
+1 −0 internal/ls/displaypartswriter.go
+215 −1 internal/ls/findallreferences.go
+197 −86 internal/ls/hover.go
+7 −11 internal/ls/signaturehelp.go
+6 −0 internal/lsp/lsproto/_generate/fetchModel.mts
+100 −0 internal/lsp/lsproto/_generate/generate.mts
+6 −0 internal/lsp/lsproto/_generate/metaModelSchema.mts
+210 −0 internal/lsp/lsproto/lsp_generated.go
+2 −0 internal/lsp/server.go
+7 −6 internal/printer/printer.go
+35 −0 testdata/baselines/reference/compiler/cjsExportGenericTypes.symbols
+37 −0 testdata/baselines/reference/compiler/cjsExportGenericTypes.types
+36 −30 testdata/baselines/reference/fourslash/signatureHelp/jsDocDontBreakWithNamespacesVS.baseline
+54 −43 testdata/baselines/reference/fourslash/signatureHelp/jsDocFunctionSignatures5VS.baseline
+248 −188 testdata/baselines/reference/fourslash/signatureHelp/jsDocFunctionSignatures6VS.baseline
+34 −25 testdata/baselines/reference/fourslash/signatureHelp/jsdocReturnsTagVS.baseline
+80 −56 testdata/baselines/reference/fourslash/signatureHelp/quickInfoJsDocTags13VS.baseline
+150 −115 testdata/baselines/reference/fourslash/signatureHelp/quickInfoJsDocTextFormatting1VS.baseline
+480 −384 testdata/baselines/reference/fourslash/signatureHelp/signatureHelpAfterParameterVS.baseline
+30 −23 testdata/baselines/reference/fourslash/signatureHelp/signatureHelpAnonymousTypeVS.baseline
+682 −405 testdata/baselines/reference/fourslash/signatureHelp/signatureHelpBindingPatternVS.baseline
+332 −234 testdata/baselines/reference/fourslash/signatureHelp/signatureHelpCommentsClassMembersVS.baseline
+80 −64 testdata/baselines/reference/fourslash/signatureHelp/signatureHelpCommentsClassVS.baseline
+1,830 −1,391 testdata/baselines/reference/fourslash/signatureHelp/signatureHelpCommentsCommentParsingVS.baseline
+92 −70 testdata/baselines/reference/fourslash/signatureHelp/signatureHelpCommentsFunctionDeclarationVS.baseline
+80 −60 testdata/baselines/reference/fourslash/signatureHelp/signatureHelpCommentsFunctionExpressionVS.baseline
+20 −14 testdata/baselines/reference/fourslash/signatureHelp/signatureHelpConstructorCallParamPropertiesVS.baseline
+2,148 −1,626 testdata/baselines/reference/fourslash/signatureHelp/signatureHelpExpandedRestTuplesLocalLabels1VS.baseline
+20 −14 testdata/baselines/reference/fourslash/signatureHelp/signatureHelpInferenceJsDocImportTagVS.baseline
+496 −312 testdata/baselines/reference/fourslash/signatureHelp/signatureHelpIteratorNextVS.baseline
+144 −108 testdata/baselines/reference/fourslash/signatureHelp/signatureHelpJSDocCallbackTagVS.baseline
+56 −44 testdata/baselines/reference/fourslash/signatureHelp/signatureHelpJSDocTagsVS.baseline
+186 −109 testdata/baselines/reference/fourslash/signatureHelp/signatureHelpJSMissingPropertyAccessVS.baseline
+200 −160 testdata/baselines/reference/fourslash/signatureHelp/signatureHelpRestArgs1VS.baseline
+36 −26 testdata/baselines/reference/fourslash/signatureHelp/signatureHelpRestArgs2VS.baseline
+246 −191 testdata/baselines/reference/fourslash/signatureHelp/signatureHelpRestArgs3VS.baseline
+200 −160 testdata/baselines/reference/fourslash/signatureHelp/signatureHelpSkippedArgs1VS.baseline
+232 −212 testdata/baselines/reference/fourslash/signatureHelp/signatureHelpTypeArguments2VS.baseline
+20 −14 testdata/baselines/reference/fourslash/signatureHelp/signatureHelpWithUnknownVS.baseline
+138 −81 testdata/baselines/reference/fourslash/signatureHelp/signatureHelp_unionTypeVS.baseline
+70 −51 testdata/baselines/reference/fourslash/signatureHelp/trailingCommaSignatureHelpVS.baseline
+68 −0 testdata/baselines/reference/fourslash/vsFindAllReferences/constructorFindAllReferences1VS.baseline
+290 −0 testdata/baselines/reference/fourslash/vsFindAllReferences/findAllRefsForDefaultExportVS.baseline
+409 −0 testdata/baselines/reference/fourslash/vsFindAllReferences/findAllRefsInheritedProperties1VS.baseline
+417 −0 testdata/baselines/reference/fourslash/vsFindAllReferences/findReferencesAcrossMultipleProjectsVS.baseline
+361 −0 testdata/baselines/reference/fourslash/vsFindAllReferences/tsxFindAllReferences1VS.baseline
+25 −0 testdata/tests/cases/compiler/cjsExportGenericTypes.ts
7 changes: 4 additions & 3 deletions pkg/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -15691,8 +15691,9 @@ func (c *Checker) resolveEntityName(name *ast.Node, meaning ast.SymbolFlags, ign
(symbol.Flags&ast.SymbolFlagsAlias != 0 || name.Parent != nil && name.Parent.Kind == ast.KindExportAssignment) {
c.markSymbolOfAliasDeclarationIfTypeOnly(getAliasDeclarationFromName(name), nil)
}
if symbol.Flags&meaning == 0 && !dontResolveAlias && symbol.Flags&ast.SymbolFlagsAlias != 0 {
return c.resolveAlias(symbol)
// We know a symbol with the given meaning exists along the alias chain, so resolve until we find it.
for symbol.Flags&meaning == 0 && !dontResolveAlias && symbol.Flags&ast.SymbolFlagsAlias != 0 {
symbol = c.resolveAlias(symbol)
}
}
return symbol
Expand Down Expand Up @@ -30219,7 +30220,7 @@ func (c *Checker) getClassElementPropertyKeyType(element *ast.Node) *Type {
}
return c.stringType
}
panic("Unhandled case in getClassElementPropertyKeyType")
return c.errorType
}

func (c *Checker) getTypeOfPropertyOfContextualType(t *Type, name string) *Type {
Expand Down
3 changes: 2 additions & 1 deletion pkg/fourslash/baselineutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
closingTagCmd baselineCommand = "Closing Tag"
documentHighlightsCmd baselineCommand = "documentHighlights"
findAllReferencesCmd baselineCommand = "findAllReferences"
vsFindAllReferencesCmd baselineCommand = "vsFindAllReferences"
goToDefinitionCmd baselineCommand = "goToDefinition"
goToImplementationCmd baselineCommand = "goToImplementation"
goToSourceDefinitionCmd baselineCommand = "goToSourceDefinition"
Expand Down Expand Up @@ -78,7 +79,7 @@ func getBaselineFileName(t *testing.T, command baselineCommand) string {

func getBaselineExtension(command baselineCommand) string {
switch command {
case quickInfoCmd, signatureHelpCmd, smartSelectionCmd, inlayHintsCmd, nonSuggestionDiagnosticsCmd, documentSymbolsCmd, closingTagCmd:
case quickInfoCmd, signatureHelpCmd, smartSelectionCmd, inlayHintsCmd, nonSuggestionDiagnosticsCmd, documentSymbolsCmd, closingTagCmd, vsFindAllReferencesCmd:
return "baseline"
case callHierarchyCmd:
return "callHierarchy.txt"
Expand Down
80 changes: 80 additions & 0 deletions pkg/fourslash/fourslash.go
Original file line number Diff line number Diff line change
Expand Up @@ -2330,6 +2330,86 @@ func (f *FourslashTest) VerifyBaselineFindAllReferences(
}
}

func (f *FourslashTest) VerifyBaselineVsFindAllReferences(
t *testing.T,
markers ...string,
) {
referenceLocations := f.lookupMarkersOrGetRanges(t, markers)

for _, markerOrRange := range referenceLocations {
f.GoToMarkerOrRange(t, markerOrRange)

params := &lsproto.ReferenceParams{
TextDocument: lsproto.TextDocumentIdentifier{
Uri: lsconv.FileNameToDocumentURI(f.activeFilename),
},
Position: f.currentCaretPosition,
Context: &lsproto.ReferenceContext{
IncludeDeclaration: true,
},
}
result := sendRequest(t, f, lsproto.TextDocumentVSReferencesInfo, params)
// Sort cross-project results for deterministic baselines
if result.VsReferenceItems != nil && len(*result.VsReferenceItems) > 0 {
items := *result.VsReferenceItems
slices.SortStableFunc(items, func(a, b *lsproto.VsReferenceItem) int {
ap, bp := "", ""
if a.VSProjectName != nil {
ap = *a.VSProjectName
}
if b.VSProjectName != nil {
bp = *b.VSProjectName
}
if ap != bp {
if ap < bp {
return -1
}
return 1
}
if a.VSLocation.Uri != b.VSLocation.Uri {
if string(a.VSLocation.Uri) < string(b.VSLocation.Uri) {
return -1
}
return 1
}
if a.VSLocation.Range.Start.Line != b.VSLocation.Range.Start.Line {
return int(a.VSLocation.Range.Start.Line) - int(b.VSLocation.Range.Start.Line)
}
return int(a.VSLocation.Range.Start.Character) - int(b.VSLocation.Range.Start.Character)
})
// Re-number IDs sequentially after sort
idRemap := make(map[int32]int32, len(items))
for i, item := range items {
idRemap[item.VSId] = int32(i)
item.VSId = int32(i)
}
for _, item := range items {
if item.VSDefinitionId != nil {
newDefId := idRemap[*item.VSDefinitionId]
item.VSDefinitionId = &newDefId
}
}
}
// Include file contents with markers
var locations []lsproto.Location
if result.VsReferenceItems != nil {
for _, item := range *result.VsReferenceItems {
locations = append(locations, item.VSLocation)
}
}
fileContents := f.getBaselineForLocationsWithFileContents(locations, baselineFourslashLocationsOptions{
marker: markerOrRange,
markerName: "/*FIND ALL REFS*/",
})

if jsonStr, err := core.StringifyJson(result, "", " "); err == nil {
f.addResultToBaseline(t, vsFindAllReferencesCmd, fileContents+"\n\n"+jsonStr)
} else {
t.Fatalf("Failed to stringify VS references result for baseline: %v", err)
}
}
}

func (f *FourslashTest) VerifyBaselineCodeLens(t *testing.T, preferences *lsutil.UserPreferences) {
if preferences != nil {
reset := f.ConfigureWithReset(t, *preferences)
Expand Down
23 changes: 23 additions & 0 deletions pkg/fourslash/tests/constructorFindAllReferences1VS_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package fourslash_test

import (
"testing"

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

func TestConstructorFindAllReferences1VS(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `export class C {
/**/public constructor() { }
public foo() { }
}

new C().foo();`
f, done := fourslash.NewFourslash(t, &lsproto.ClientCapabilities{VSSupportsVisualStudioExtensions: new(true)}, content)
defer done()
f.VerifyBaselineVsFindAllReferences(t, "")
}
36 changes: 36 additions & 0 deletions pkg/fourslash/tests/decoratorOnPrivateMethod_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package fourslash_test

import (
"testing"

"github.com/buke/typescript-go-internal/pkg/fourslash"
. "github.com/buke/typescript-go-internal/pkg/fourslash/tests/util"
"github.com/buke/typescript-go-internal/pkg/testutil"
)

func TestDecoratorCompletionOnPrivateMethod(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `
// @experimentalDecorators: true
declare function dec(target: any, key: string): void;
class C {
@dec/**/
#method() {}
}`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()
// Verify completions don't panic on decorator applied to private method
f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{
IsIncomplete: false,
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
CommitCharacters: &DefaultCommitCharacters,
EditRange: Ignored,
},
Items: &fourslash.CompletionsExpectedItems{
Includes: []fourslash.CompletionsExpectedItem{
"dec",
},
},
})
}
24 changes: 24 additions & 0 deletions pkg/fourslash/tests/findAllRefsForDefaultExportVS_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package fourslash_test

import (
"testing"

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

func TestFindAllRefsForDefaultExportVS(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @Filename: a.ts
export default function /*def*/f() {}
// @Filename: b.ts
import /*deg*/g from "./a";
[|/*ref*/g|]();
// @Filename: c.ts
import { f } from "./a";`
f, done := fourslash.NewFourslash(t, &lsproto.ClientCapabilities{VSSupportsVisualStudioExtensions: new(true)}, content)
defer done()
f.VerifyBaselineVsFindAllReferences(t, "def", "deg")
}
25 changes: 25 additions & 0 deletions pkg/fourslash/tests/findAllRefsInheritedProperties1VS_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package fourslash_test

import (
"testing"

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

func TestFindAllRefsInheritedProperties1VS(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `class class1 extends class1 {
/*1*/doStuff() { }
/*2*/propName: string;
}

var v: class1;
v./*3*/doStuff();
v./*4*/propName;`
f, done := fourslash.NewFourslash(t, &lsproto.ClientCapabilities{VSSupportsVisualStudioExtensions: new(true)}, content)
defer done()
f.VerifyBaselineVsFindAllReferences(t, "1", "2", "3", "4")
}
25 changes: 25 additions & 0 deletions pkg/fourslash/tests/findReferencesAcrossMultipleProjectsVS_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package fourslash_test

import (
"testing"

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

func TestFindReferencesAcrossMultipleProjectsVS(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `//@Filename: a.ts
/*1*/var /*2*/x: number;
//@Filename: b.ts
/// <reference path="a.ts" />
/*3*/x++;
//@Filename: c.ts
/// <reference path="a.ts" />
/*4*/x++;`
f, done := fourslash.NewFourslash(t, &lsproto.ClientCapabilities{VSSupportsVisualStudioExtensions: new(true)}, content)
defer done()
f.VerifyBaselineVsFindAllReferences(t, "1", "2", "3", "4")
}
29 changes: 29 additions & 0 deletions pkg/fourslash/tests/tsxFindAllReferences1VS_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package fourslash_test

import (
"testing"

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

func TestTsxFindAllReferences1VS(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `//@Filename: file.tsx
declare namespace JSX {
interface Element { }
interface IntrinsicElements {
/*1*/div: {
name?: string;
isOpen?: boolean;
};
span: { n: string; };
}
}
var x = /*2*/</*3*/div />;`
f, done := fourslash.NewFourslash(t, &lsproto.ClientCapabilities{VSSupportsVisualStudioExtensions: new(true)}, content)
defer done()
f.VerifyBaselineVsFindAllReferences(t, "1", "2", "3")
}
28 changes: 28 additions & 0 deletions pkg/ls/crossproject.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,34 @@ func combineReferences(results iter.Seq[lsproto.ReferencesResponse]) lsproto.Ref
return lsproto.LocationsOrNull{Locations: combineResponseLocations(results)}
}

func combineVsReferences(results iter.Seq[lsproto.VsReferencesResponse]) lsproto.VsReferencesResponse {
var combined []*lsproto.VsReferenceItem
// Re-number IDs across projects to maintain unique IDs and correct definition references
nextId := int32(0)
for resp := range results {
if resp.VsReferenceItems == nil {
continue
}
// Map old IDs to new IDs for this batch
idMap := make(map[int32]int32)
for _, item := range *resp.VsReferenceItems {
oldId := item.VSId
newId := nextId
idMap[oldId] = newId
nextId++

newItem := *item
newItem.VSId = newId
if item.VSDefinitionId != nil {
newDefId := idMap[*item.VSDefinitionId]
newItem.VSDefinitionId = &newDefId
}
combined = append(combined, &newItem)
}
}
return lsproto.VsReferencesResponse{VsReferenceItems: &combined}
}

func combineImplementations(results iter.Seq[lsproto.ImplementationResponse]) lsproto.ImplementationResponse {
var combined []*lsproto.LocationLink
var seenLocations collections.Set[lsproto.Location]
Expand Down
1 change: 1 addition & 0 deletions pkg/ls/displaypartswriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func (w *displayPartsWriter) addRun(classification lsproto.ClassificationTypeNam
w.runs = append(w.runs, &lsproto.ClassifiedTextRun{
ClassificationTypeName: string(classification),
Text: text,
VSType: "ClassifiedTextRun",
})
}
w.lastWritten = text
Expand Down
Loading