mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-10-28 16:36:04 +08:00
Exclude top-level imports from document symbols (#64160)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
This commit is contained in:
1 parent
1a78786ca7
commit
21b260b4e7
6 files changed
+51
-30
No files matched your search
@@ -0,0 +1,27 @@
|
||||
package fourslash_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/microsoft/TypeScript/tsc/internal/fourslash"
|
||||
"github.com/microsoft/TypeScript/tsc/internal/testutil"
|
||||
)
|
||||
|
||||
func TestDocumentSymbolTopLevelImports(t *testing.T) {
|
||||
t.Parallel()
|
||||
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
|
||||
const content = `/** @typedef {number} ImportedType */
|
||||
import DefaultComponent from "./component";
|
||||
/** @callback ImportedCallback
|
||||
* @param {string} value
|
||||
* @returns {number}
|
||||
*/
|
||||
import * as utils from "./utils";
|
||||
import { value, original as renamed } from "./values";
|
||||
import type { Options } from "./types";
|
||||
|
||||
const local = 1;`
|
||||
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
|
||||
defer done()
|
||||
f.VerifyBaselineDocumentSymbol(t)
|
||||
}
|
||||
@@ -161,6 +161,9 @@ func (l *LanguageService) getDocumentSymbolsForChildren(ctx context.Context, nod
|
||||
}
|
||||
}
|
||||
}
|
||||
if node.Parent.Kind == ast.KindSourceFile && ast.IsImportOrImportEqualsDeclaration(node) {
|
||||
return false
|
||||
}
|
||||
switch node.Kind {
|
||||
case ast.KindClassDeclaration, ast.KindClassExpression, ast.KindInterfaceDeclaration, ast.KindEnumDeclaration:
|
||||
if ast.IsClassLike(node) && ast.GetDeclarationName(node) != "" {
|
||||
|
||||
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
// === Document Symbols ===
|
||||
// === /documentSymbolTopLevelImports.ts ===
|
||||
// /** <|@typedef {number} [|{| name: ImportedType, kind: Class |}ImportedType|]|> */
|
||||
// import DefaultComponent from "./component";
|
||||
// /** <|@callback [|{| name: ImportedCallback, kind: Class |}ImportedCallback|]
|
||||
// * @param {string} value
|
||||
// * @returns {number}
|
||||
// |>*/
|
||||
// import * as utils from "./utils";
|
||||
// import { value, original as renamed } from "./values";
|
||||
// import type { Options } from "./types";
|
||||
//
|
||||
// const <|[|{| name: local, kind: Variable |}local|] = 1|>;
|
||||
|
||||
// === Details ===
|
||||
(Class) ImportedType
|
||||
(Class) ImportedCallback
|
||||
(Variable) local
|
||||
+1
-8
@@ -1,11 +1,4 @@
|
||||
// === Document Symbols ===
|
||||
// === /navigationBarImports.ts ===
|
||||
// import <|[|{| name: a, kind: Variable |}a|]|>, {<|[|{| name: b, kind: Variable |}b|]|>} from "m";
|
||||
// <|import [|{| name: c, kind: Variable |}c|] = require("m");|>
|
||||
// import <|* as [|{| name: d, kind: Variable |}d|]|> from "m";
|
||||
|
||||
|
||||
// === Details ===
|
||||
(Variable) a
|
||||
(Variable) b
|
||||
(Variable) c
|
||||
(Variable) d
|
||||
Vendored
+1
-2
@@ -4,11 +4,10 @@
|
||||
//
|
||||
// export { <|b as [|{| name: B, kind: Variable |}B|]|> } from "a"
|
||||
//
|
||||
// <|export import [|{| name: e, kind: Variable |}e|] = require("a");|>
|
||||
// export import e = require("a");
|
||||
//
|
||||
// export * from "a"; // no bindings here
|
||||
|
||||
// === Details ===
|
||||
(Variable) a
|
||||
(Variable) B
|
||||
(Variable) e
|
||||
Vendored
+1
-20
@@ -1,23 +1,4 @@
|
||||
// === Document Symbols ===
|
||||
// === /navigationBarItemsImports.ts ===
|
||||
// import <|[|{| name: d1, kind: Variable |}d1|]|> from "a";
|
||||
//
|
||||
// import { <|[|{| name: a, kind: Variable |}a|]|> } from "a";
|
||||
//
|
||||
// import { <|b as [|{| name: B, kind: Variable |}B|]|> } from "a"
|
||||
//
|
||||
// import <|[|{| name: d2, kind: Variable |}d2|]|>, { <|[|{| name: c, kind: Variable |}c|]|>, <|d as [|{| name: D, kind: Variable |}D|]|> } from "a"
|
||||
//
|
||||
// <|import [|{| name: e, kind: Variable |}e|] = require("a");|>
|
||||
//
|
||||
// import <|* as [|{| name: ns, kind: Variable |}ns|]|> from "a";
|
||||
|
||||
|
||||
// === Details ===
|
||||
(Variable) d1
|
||||
(Variable) a
|
||||
(Variable) B
|
||||
(Variable) d2
|
||||
(Variable) c
|
||||
(Variable) D
|
||||
(Variable) e
|
||||
(Variable) ns
|
||||
Reference in new issue
Block a user