diff --git a/internal/fourslash/tests/manual/findAllReferencesJSDocPrivateIdentifier_test.go b/internal/fourslash/tests/manual/findAllReferencesJSDocPrivateIdentifier_test.go new file mode 100644 index 00000000000..b169341d94f --- /dev/null +++ b/internal/fourslash/tests/manual/findAllReferencesJSDocPrivateIdentifier_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllReferencesJSDocPrivateIdentifier(t *testing.T) { + t.Parallel() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` +class C { + /*1*/#field; + /** + * @see C./*2*/#field + */ + method() {} +} +` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + + f.VerifyBaselineFindAllReferences(t, "1", "2") +} diff --git a/internal/ls/findallreferences.go b/internal/ls/findallreferences.go index 28043f859dd..7744ceb23e6 100644 --- a/internal/ls/findallreferences.go +++ b/internal/ls/findallreferences.go @@ -348,10 +348,9 @@ func getRangeOfNode(node *ast.Node, sourceFile *ast.SourceFile, endNode *ast.Nod func isValidReferencePosition(node *ast.Node, searchSymbolName string) bool { switch node.Kind { case ast.KindPrivateIdentifier: - // !!! - // if (isJSDocMemberName(node.Parent)) { - // return true; - // } + if isJSDocMemberName(node.Parent) { + return true + } return len(node.Text()) == len(searchSymbolName) case ast.KindIdentifier: return len(node.Text()) == len(searchSymbolName) @@ -2652,3 +2651,16 @@ func (state *refState) explicitlyInheritsFrom(symbol *ast.Symbol, parent *ast.Sy state.inheritsFromCache[key] = inherits return inherits } + +func isJSDocMemberName(node *ast.Node) bool { + if node == nil { + return false + } + if node.Kind == ast.KindIdentifier || node.Kind == ast.KindPrivateIdentifier { + return true + } + if node.Kind == ast.KindPropertyAccessExpression { + return isJSDocMemberName(node.AsPropertyAccessExpression().Name()) + } + return false +} diff --git a/testdata/baselines/reference/submodule/fourslash/findAllReferences/findAllReferencesJSDocPrivateIdentifier.baseline.jsonc b/testdata/baselines/reference/submodule/fourslash/findAllReferences/findAllReferencesJSDocPrivateIdentifier.baseline.jsonc new file mode 100644 index 00000000000..df1a0be51b0 --- /dev/null +++ b/testdata/baselines/reference/submodule/fourslash/findAllReferences/findAllReferencesJSDocPrivateIdentifier.baseline.jsonc @@ -0,0 +1,23 @@ +// === findAllReferences === +// === /findAllReferencesJSDocPrivateIdentifier.ts === +// +// class C { +// /*FIND ALL REFS*/[|#field|]; +// /** +// * @see C.#field +// */ +// --- (line: 7) skipped --- + + + +// === findAllReferences === +// === /findAllReferencesJSDocPrivateIdentifier.ts === +// +// class C { +// #field; +// /** +// * @see C./*FIND ALL REFS*/#field +// */ +// method() {} +// } +// \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/fourslash/findAllReferences/findAllReferencesJSDocPrivateIdentifier.baseline.jsonc.diff b/testdata/baselines/reference/submoduleAccepted/fourslash/findAllReferences/findAllReferencesJSDocPrivateIdentifier.baseline.jsonc.diff new file mode 100644 index 00000000000..541f11fa5db --- /dev/null +++ b/testdata/baselines/reference/submoduleAccepted/fourslash/findAllReferences/findAllReferencesJSDocPrivateIdentifier.baseline.jsonc.diff @@ -0,0 +1,26 @@ +--- old.findAllReferencesJSDocPrivateIdentifier.baseline.jsonc ++++ new.findAllReferencesJSDocPrivateIdentifier.baseline.jsonc +@@= skipped --1, +0 lines =@@ ++// === findAllReferences === ++// === /findAllReferencesJSDocPrivateIdentifier.ts === ++// ++// class C { ++// /*FIND ALL REFS*/[|#field|]; ++// /** ++// * @see C.#field ++// */ ++// --- (line: 7) skipped --- ++ ++ ++ ++// === findAllReferences === ++// === /findAllReferencesJSDocPrivateIdentifier.ts === ++// ++// class C { ++// #field; ++// /** ++// * @see C./*FIND ALL REFS*/#field ++// */ ++// method() {} ++// } ++// \ No newline at end of file diff --git a/testdata/submoduleAccepted.txt b/testdata/submoduleAccepted.txt index b979f793aaa..8e69a76ef8f 100644 --- a/testdata/submoduleAccepted.txt +++ b/testdata/submoduleAccepted.txt @@ -1412,3 +1412,4 @@ conformance/callbackTagVariadicType.js.diff # definiteAssignment shorthand in object literal loses optional modifier ## https://github.com/microsoft/typescript-go/issues/3563 conformance/definiteAssignmentAssertionsWithObjectShortHand.js.diff +fourslash/findAllReferences/findAllReferencesJSDocPrivateIdentifier.baseline.jsonc.diff