mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-10 15:25:54 -06:00
Add outlining span for named bindings in import declarations
This commit is contained in:
parent
de13cc4692
commit
2d725feb51
@ -33,8 +33,16 @@ namespace ts.OutliningElementsCollector {
|
||||
// Add outlining spans for comments if they exist
|
||||
addOutliningForLeadingCommentsForNode(node, sourceFile, cancellationToken, out);
|
||||
// Add outlining spans for the import statement itself if applicable
|
||||
const span = getOutliningSpanForNode(node, sourceFile);
|
||||
if (span) out.push(span);
|
||||
if (isImportDeclaration(node) && node.importClause && node.importClause.namedBindings &&
|
||||
node.importClause.namedBindings.kind !== SyntaxKind.NamespaceImport && node.importClause.namedBindings.elements.length) {
|
||||
const openToken = findChildOfKind(node.importClause.namedBindings, SyntaxKind.OpenBraceToken, sourceFile);
|
||||
const closeToken = findChildOfKind(node.importClause.namedBindings, SyntaxKind.CloseBraceToken, sourceFile);
|
||||
if (openToken && closeToken) {
|
||||
out.push(createOutliningSpan(
|
||||
createTextSpanFromBounds(openToken.getStart(sourceFile), closeToken.getEnd()),
|
||||
OutliningSpanKind.Import, createTextSpanFromNode(node, sourceFile)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function visitNonImportNode(n: Node) {
|
||||
@ -177,10 +185,7 @@ namespace ts.OutliningElementsCollector {
|
||||
return spanForObjectOrArrayLiteral(n);
|
||||
case SyntaxKind.ArrayLiteralExpression:
|
||||
return spanForObjectOrArrayLiteral(n, SyntaxKind.OpenBracketToken);
|
||||
case SyntaxKind.ImportDeclaration:
|
||||
const importClause = (n as ImportDeclaration).importClause;
|
||||
return importClause && importClause.namedBindings && importClause.namedBindings.kind !== SyntaxKind.NamespaceImport ? spanForNode(importClause.namedBindings) : undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function spanForObjectOrArrayLiteral(node: Node, open: SyntaxKind.OpenBraceToken | SyntaxKind.OpenBracketToken = SyntaxKind.OpenBraceToken): OutliningSpan | undefined {
|
||||
// If the block has no leading keywords and is inside an array literal,
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
////[|import * as ns from "mod";
|
||||
////
|
||||
////import d from "mod";
|
||||
////import { a, b, c } from "mod";
|
||||
////import [|{ a, b, c }|] from "mod";
|
||||
////
|
||||
////import r = require("mod");|]
|
||||
////
|
||||
@ -14,7 +14,7 @@
|
||||
////// another set of imports
|
||||
////[|import * as ns from "mod";
|
||||
////import d from "mod";
|
||||
////import { a, b, c } from "mod";
|
||||
////import [|{ a, b, c }|] from "mod";
|
||||
////import r = require("mod");|]
|
||||
|
||||
verify.outliningSpansInCurrentFile(test.ranges(), "import");
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
|
||||
////[|import [|{
|
||||
//// a,
|
||||
//// b as B,
|
||||
//// c
|
||||
////}|] from "mod";
|
||||
////
|
||||
////
|
||||
////import { } from "mod";
|
||||
////import * as ns from "mod";
|
||||
////import d from "mod";|]
|
||||
|
||||
verify.outliningSpansInCurrentFile(test.ranges(), "import");
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user