Skip to content

Commit 5c98631

Browse files
committed
more maybe
1 parent c808430 commit 5c98631

File tree

58 files changed

+307
-445
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+307
-445
lines changed

internal/fourslash/_scripts/failingTests.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ TestGetJavaScriptQuickInfo8
198198
TestGetJavaScriptSyntacticDiagnostics24
199199
TestGetOccurrencesIfElseBroken
200200
TestGetQuickInfoForIntersectionTypes
201+
TestGetRenameInfoTests1
201202
TestHoverOverComment
202203
TestImportCompletionsPackageJsonExportsSpecifierEndsInTs
203204
TestImportCompletionsPackageJsonExportsTrailingSlash1
@@ -433,6 +434,7 @@ TestReferencesForStatementKeywords
433434
TestReferencesInEmptyFile
434435
TestRegexDetection
435436
TestRenameForAliasingExport02
437+
TestRenameForDefaultExport04
436438
TestRenameFromNodeModulesDep1
437439
TestRenameFromNodeModulesDep2
438440
TestRenameFromNodeModulesDep3

internal/ls/findallreferences.go

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,7 @@ func getReferencedSymbolsSpecial(node *ast.Node, sourceFiles []*ast.SourceFile)
727727
}
728728

729729
if ast.IsImportMeta(node.Parent) && node.Parent.Name() == node {
730-
// !!! unimplemented
731-
return nil // getAllReferencesForImportMeta(sourceFiles /*, cancellationToken*/)
730+
return getAllReferencesForImportMeta(sourceFiles)
732731
}
733732

734733
if node.Kind == ast.KindStaticKeyword && node.Parent.Kind == ast.KindClassStaticBlockDeclaration {
@@ -887,6 +886,22 @@ func getReferencesForSuperKeyword(superKeyword *ast.Node) []*SymbolAndEntries {
887886
return []*SymbolAndEntries{NewSymbolAndEntries(definitionKindSymbol, nil, searchSpaceNode.Symbol(), references)}
888887
}
889888

889+
func getAllReferencesForImportMeta(sourceFiles []*ast.SourceFile) []*SymbolAndEntries {
890+
references := core.FlatMap(sourceFiles, func(sourceFile *ast.SourceFile) []*referenceEntry {
891+
return core.MapNonNil(getPossibleSymbolReferenceNodes(sourceFile, "meta", sourceFile.AsNode()), func(node *ast.Node) *referenceEntry {
892+
parent := node.Parent
893+
if ast.IsImportMeta(parent) {
894+
return newNodeEntry(parent)
895+
}
896+
return nil
897+
})
898+
})
899+
if len(references) == 0 {
900+
return nil
901+
}
902+
return []*SymbolAndEntries{{definition: &Definition{Kind: definitionKindKeyword, node: references[0].node}, references: references}}
903+
}
904+
890905
func getAllReferencesForKeyword(sourceFiles []*ast.SourceFile, keywordKind ast.Kind, filterReadOnlyTypeOperator bool) []*SymbolAndEntries {
891906
// references is a list of NodeEntry
892907
references := core.FlatMap(sourceFiles, func(sourceFile *ast.SourceFile) []*referenceEntry {
@@ -1117,6 +1132,24 @@ func getReferenceAtPosition(sourceFile *ast.SourceFile, position int, program *c
11171132
}
11181133

11191134
// -- Core algorithm for find all references --
1135+
func getSpecialSearchKind(node *ast.Node) string {
1136+
if node == nil {
1137+
return "none"
1138+
}
1139+
switch node.Kind {
1140+
case ast.KindConstructor, ast.KindConstructorKeyword:
1141+
return "constructor"
1142+
case ast.KindIdentifier:
1143+
if ast.IsClassLike(node.Parent) {
1144+
debug.Assert(node.Parent.Name() == node)
1145+
return "class"
1146+
}
1147+
fallthrough
1148+
default:
1149+
return "none"
1150+
}
1151+
}
1152+
11201153
func getReferencedSymbolsForSymbol(originalSymbol *ast.Symbol, node *ast.Node, sourceFiles []*ast.SourceFile, sourceFilesSet *collections.Set[string], checker *checker.Checker, options refOptions) []*SymbolAndEntries {
11211154
// Core find-all-references algorithm for a normal symbol.
11221155

@@ -1137,8 +1170,7 @@ func getReferencedSymbolsForSymbol(originalSymbol *ast.Symbol, node *ast.Node, s
11371170
// state.getReferencesAtExportSpecifier(exportSpecifier.Name(), symbol, exportSpecifier.AsExportSpecifier(), state.createSearch(node, originalSymbol, comingFromUnknown /*comingFrom*/, "", nil), true /*addReferencesHere*/, true /*alwaysGetReferences*/)
11381171
} else if node != nil && node.Kind == ast.KindDefaultKeyword && symbol.Name == ast.InternalSymbolNameDefault && symbol.Parent != nil {
11391172
state.addReference(node, symbol, entryKindNone)
1140-
// !!! not implemented
1141-
// state.searchForImportsOfExport(node, symbol, &ExportInfo{exportingModuleSymbol: symbol.Parent, exportKind: ExportKindDefault})
1173+
state.searchForImportsOfExport(node, symbol, &ExportInfo{exportingModuleSymbol: symbol.Parent, exportKind: ExportKindDefault})
11421174
} else {
11431175
search := state.createSearch(node, symbol, ImpExpKindUnknown /*comingFrom*/, "", state.populateSearchSymbolSet(symbol, node, options.use == referenceUseRename, options.useAliasesForRename, options.implementations))
11441176
state.getReferencesInContainerOrFiles(symbol, search)
@@ -1193,7 +1225,7 @@ func newState(sourceFiles []*ast.SourceFile, sourceFilesSet *collections.Set[str
11931225
return &refState{
11941226
sourceFiles: sourceFiles,
11951227
sourceFilesSet: sourceFilesSet,
1196-
specialSearchKind: "none", // !!! other search kinds not implemented
1228+
specialSearchKind: getSpecialSearchKind(node),
11971229
checker: checker,
11981230
searchMeaning: searchMeaning,
11991231
options: options,
@@ -1275,6 +1307,21 @@ func (state *refState) addReference(referenceLocation *ast.Node, symbol *ast.Sym
12751307
}
12761308
}
12771309

1310+
func getReferenceEntriesForShorthandPropertyAssignment(node *ast.Node, checker *checker.Checker, addReference func(*ast.Node)) {
1311+
refSymbol := checker.GetSymbolAtLocation(node)
1312+
if refSymbol == nil || refSymbol.ValueDeclaration == nil {
1313+
return
1314+
}
1315+
shorthandSymbol := checker.GetShorthandAssignmentValueSymbol(refSymbol.ValueDeclaration)
1316+
if shorthandSymbol != nil && len(shorthandSymbol.Declarations) > 0 {
1317+
for _, declaration := range shorthandSymbol.Declarations {
1318+
if getMeaningFromDeclaration(declaration)&ast.SemanticMeaningValue != 0 {
1319+
addReference(declaration)
1320+
}
1321+
}
1322+
}
1323+
}
1324+
12781325
func (state *refState) addImplementationReferences(refNode *ast.Node, addRef func(*ast.Node)) {
12791326
// Check if we found a function/propertyAssignment/method with an implementation or initializer
12801327
if ast.IsDeclarationName(refNode) && isImplementation(refNode.Parent) {
@@ -1288,9 +1335,7 @@ func (state *refState) addImplementationReferences(refNode *ast.Node, addRef fun
12881335

12891336
if refNode.Parent.Kind == ast.KindShorthandPropertyAssignment {
12901337
// Go ahead and dereference the shorthand assignment by going to its definition
1291-
1292-
// !!! not implemented
1293-
// getReferenceEntriesForShorthandPropertyAssignment(refNode, state.checker, addRef);
1338+
getReferenceEntriesForShorthandPropertyAssignment(refNode, state.checker, addRef)
12941339
}
12951340

12961341
// Check if the node is within an extends or implements clause

testdata/baselines/reference/fourslash/documentHighlights/documentHighlightInExport1.baseline.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// === documentHighlights ===
22
// === /documentHighlightInExport1.ts ===
3-
// class /*HIGHLIGHTS*/[|C|] {}
3+
// class /*HIGHLIGHTS*/C {}
44
// export { C as D };
55

66

testdata/baselines/reference/fourslash/documentHighlights/getOccurrencesClassExpressionConstructor.baseline.jsonc

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,52 @@
11
// === documentHighlights ===
22
// === /getOccurrencesClassExpressionConstructor.ts ===
3-
// let A = class [|Foo|] {
4-
// /*HIGHLIGHTS*/constructor();
5-
// constructor(x: number);
6-
// constructor(y: string);
7-
// constructor(a?: any) {
8-
// // --- (line: 6) skipped ---
3+
// let A = class Foo {
4+
// /*HIGHLIGHTS*/[|constructor|]();
5+
// [|constructor|](x: number);
6+
// [|constructor|](y: string);
7+
// [|constructor|](a?: any) {
8+
// }
9+
// }
10+
//
11+
// // --- (line: 9) skipped ---
912

1013

1114

1215
// === documentHighlights ===
1316
// === /getOccurrencesClassExpressionConstructor.ts ===
14-
// let A = class [|Foo|] {
15-
// constructor();
16-
// /*HIGHLIGHTS*/constructor(x: number);
17-
// constructor(y: string);
18-
// constructor(a?: any) {
17+
// let A = class Foo {
18+
// [|constructor|]();
19+
// /*HIGHLIGHTS*/[|constructor|](x: number);
20+
// [|constructor|](y: string);
21+
// [|constructor|](a?: any) {
1922
// }
20-
// // --- (line: 7) skipped ---
23+
// }
24+
//
25+
// // --- (line: 9) skipped ---
2126

2227

2328

2429
// === documentHighlights ===
2530
// === /getOccurrencesClassExpressionConstructor.ts ===
26-
// let A = class [|Foo|] {
27-
// constructor();
28-
// constructor(x: number);
29-
// /*HIGHLIGHTS*/constructor(y: string);
30-
// constructor(a?: any) {
31+
// let A = class Foo {
32+
// [|constructor|]();
33+
// [|constructor|](x: number);
34+
// /*HIGHLIGHTS*/[|constructor|](y: string);
35+
// [|constructor|](a?: any) {
3136
// }
3237
// }
33-
// // --- (line: 8) skipped ---
38+
//
39+
// // --- (line: 9) skipped ---
3440

3541

3642

3743
// === documentHighlights ===
3844
// === /getOccurrencesClassExpressionConstructor.ts ===
39-
// let A = class [|Foo|] {
40-
// constructor();
41-
// constructor(x: number);
42-
// constructor(y: string);
43-
// /*HIGHLIGHTS*/constructor(a?: any) {
45+
// let A = class Foo {
46+
// [|constructor|]();
47+
// [|constructor|](x: number);
48+
// [|constructor|](y: string);
49+
// /*HIGHLIGHTS*/[|constructor|](a?: any) {
4450
// }
4551
// }
4652
//

testdata/baselines/reference/fourslash/documentHighlights/getOccurrencesConstructor.baseline.jsonc

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,52 @@
11
// === documentHighlights ===
22
// === /getOccurrencesConstructor.ts ===
3-
// class [|C|] {
4-
// /*HIGHLIGHTS*/constructor();
5-
// constructor(x: number);
6-
// constructor(y: string, x: number);
7-
// constructor(a?: any, ...r: any[]) {
8-
// // --- (line: 6) skipped ---
3+
// class C {
4+
// /*HIGHLIGHTS*/[|constructor|]();
5+
// [|constructor|](x: number);
6+
// [|constructor|](y: string, x: number);
7+
// [|constructor|](a?: any, ...r: any[]) {
8+
// if (a === undefined && r.length === 0) {
9+
// return;
10+
// }
11+
// // --- (line: 9) skipped ---
912

1013

1114

1215
// === documentHighlights ===
1316
// === /getOccurrencesConstructor.ts ===
14-
// class [|C|] {
15-
// constructor();
16-
// /*HIGHLIGHTS*/constructor(x: number);
17-
// constructor(y: string, x: number);
18-
// constructor(a?: any, ...r: any[]) {
17+
// class C {
18+
// [|constructor|]();
19+
// /*HIGHLIGHTS*/[|constructor|](x: number);
20+
// [|constructor|](y: string, x: number);
21+
// [|constructor|](a?: any, ...r: any[]) {
1922
// if (a === undefined && r.length === 0) {
20-
// // --- (line: 7) skipped ---
23+
// return;
24+
// }
25+
// // --- (line: 9) skipped ---
2126

2227

2328

2429
// === documentHighlights ===
2530
// === /getOccurrencesConstructor.ts ===
26-
// class [|C|] {
27-
// constructor();
28-
// constructor(x: number);
29-
// /*HIGHLIGHTS*/constructor(y: string, x: number);
30-
// constructor(a?: any, ...r: any[]) {
31+
// class C {
32+
// [|constructor|]();
33+
// [|constructor|](x: number);
34+
// /*HIGHLIGHTS*/[|constructor|](y: string, x: number);
35+
// [|constructor|](a?: any, ...r: any[]) {
3136
// if (a === undefined && r.length === 0) {
3237
// return;
33-
// // --- (line: 8) skipped ---
38+
// }
39+
// // --- (line: 9) skipped ---
3440

3541

3642

3743
// === documentHighlights ===
3844
// === /getOccurrencesConstructor.ts ===
39-
// class [|C|] {
40-
// constructor();
41-
// constructor(x: number);
42-
// constructor(y: string, x: number);
43-
// /*HIGHLIGHTS*/constructor(a?: any, ...r: any[]) {
45+
// class C {
46+
// [|constructor|]();
47+
// [|constructor|](x: number);
48+
// [|constructor|](y: string, x: number);
49+
// /*HIGHLIGHTS*/[|constructor|](a?: any, ...r: any[]) {
4450
// if (a === undefined && r.length === 0) {
4551
// return;
4652
// }
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// === documentHighlights ===
22
// === /getOccurrencesConstructor2.ts ===
3-
// --- (line: 10) skipped ---
4-
// }
3+
// --- (line: 11) skipped ---
54
// }
65
//
7-
// class [|D|] {
8-
// /*HIGHLIGHTS*/constructor(public x: number, public y: number) {
6+
// class D {
7+
// /*HIGHLIGHTS*/[|constructor|](public x: number, public y: number) {
98
// }
109
// }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// === documentHighlights ===
22
// === /B.ts ===
3-
// export default class /*HIGHLIGHTS*/[|C|] {
3+
// export default class /*HIGHLIGHTS*/C {
44
// test() {
55
// }
66
// }
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// === findAllReferences ===
22
// === /constructorFindAllReferences3.ts ===
3-
// export class [|C|] {
3+
// export class C {
44
// /*FIND ALL REFS*/constructor() { }
55
// public foo() { }
66
// }
77
//
8-
// new [|C|]().foo();
8+
// new C().foo();

testdata/baselines/reference/fourslash/findAllReferences/findAllReferencesLinkTag1.baseline.jsonc

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -141,41 +141,11 @@
141141

142142
// === findAllReferences ===
143143
// === /findAllReferencesLinkTag1.ts ===
144-
// class [|C|]/*FIND ALL REFS*/ {
144+
// class C/*FIND ALL REFS*/ {
145145
// m() { }
146146
// n = 1
147147
// static s() { }
148-
// /**
149-
// * {@link m}
150-
// * @see {m}
151-
// * {@link [|C|].m}
152-
// * @see {[|C|].m}
153-
// * {@link [|C|]#m}
154-
// * @see {[|C|]#m}
155-
// * {@link [|C|].prototype.m}
156-
// * @see {[|C|].prototype.m}
157-
// */
158-
// p() { }
159-
// /**
160-
// * {@link n}
161-
// * @see {n}
162-
// * {@link [|C|].n}
163-
// * @see {[|C|].n}
164-
// * {@link [|C|]#n}
165-
// * @see {[|C|]#n}
166-
// * {@link [|C|].prototype.n}
167-
// * @see {[|C|].prototype.n}
168-
// */
169-
// q() { }
170-
// /**
171-
// * {@link s}
172-
// * @see {s}
173-
// * {@link [|C|].s}
174-
// * @see {[|C|].s}
175-
// */
176-
// r() { }
177-
// }
178-
// // --- (line: 35) skipped ---
148+
// // --- (line: 5) skipped ---
179149

180150

181151

0 commit comments

Comments
 (0)