Skip to content
Draft
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
22 changes: 22 additions & 0 deletions tsc/internal/fourslash/tests/documentSymbolTopLevelImports_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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 = `import DefaultComponent from "./component";
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)
}
3 changes: 3 additions & 0 deletions tsc/internal/ls/symbols.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ func (l *LanguageService) getDocumentSymbolsForChildren(ctx context.Context, nod
if ctx.Err() != nil {
return true
}
if node.Parent.Kind == ast.KindSourceFile && ast.IsImportOrImportEqualsDeclaration(node) {
return false
}
if node.Flags&ast.NodeFlagsReparsed == 0 {
if jsdocs := node.JSDoc(file); len(jsdocs) > 0 {
for _, jsdoc := range jsdocs {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// === Document Symbols ===
// === /documentSymbolTopLevelImports.ts ===
// import DefaultComponent from "./component";
// 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 ===
(Variable) local
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
// === Document Symbols ===
// === /navigationBarItemsImports.ts ===

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I forgot that the outline also powers the navigation bar. Maybe nobody's navigating within an import?

// 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