Skip to content

Commit 48f947f

Browse files
authored
Merge pull request microsoft#11829 from Microsoft/arozga/RemoveNavBarWhiteSpace
remove whitespace in nav bar completions
2 parents d54e889 + 59cfa2e commit 48f947f

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

src/services/navigationBar.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,9 @@ namespace ts.NavigationBar {
403403
if (getModifierFlags(node) & ModifierFlags.Default) {
404404
return "default";
405405
}
406+
// We may get a string with newlines or other whitespace in the case of an object dereference
407+
// (eg: "app\n.onactivated"), so we should remove the whitespace for readabiltiy in the
408+
// navigation bar.
406409
return getFunctionOrClassName(<ArrowFunction | FunctionExpression | ClassExpression>node);
407410
case SyntaxKind.Constructor:
408411
return "constructor";
@@ -602,7 +605,7 @@ namespace ts.NavigationBar {
602605
// See if it is of the form "<expr> = function(){...}". If so, use the text from the left-hand side.
603606
else if (node.parent.kind === SyntaxKind.BinaryExpression &&
604607
(node.parent as BinaryExpression).operatorToken.kind === SyntaxKind.EqualsToken) {
605-
return nodeText((node.parent as BinaryExpression).left);
608+
return nodeText((node.parent as BinaryExpression).left).replace(whiteSpaceRegex, "");
606609
}
607610
// See if it is a property assignment, and if so use the property name
608611
else if (node.parent.kind === SyntaxKind.PropertyAssignment && (node.parent as PropertyAssignment).name) {
@@ -620,4 +623,19 @@ namespace ts.NavigationBar {
620623
function isFunctionOrClassExpression(node: Node): boolean {
621624
return node.kind === SyntaxKind.FunctionExpression || node.kind === SyntaxKind.ArrowFunction || node.kind === SyntaxKind.ClassExpression;
622625
}
626+
627+
/**
628+
* Matches all whitespace characters in a string. Eg:
629+
*
630+
* "app.
631+
*
632+
* onactivated"
633+
*
634+
* matches because of the newline, whereas
635+
*
636+
* "app.onactivated"
637+
*
638+
* does not match.
639+
*/
640+
const whiteSpaceRegex = /\s+/g;
623641
}

tests/cases/fourslash/indentationWithBaseIndent.ts

-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@
205205
//// function unterminatedListIndentation(a,
206206
////{| "indent": 14 , "baseIndentSize": 10 |}
207207

208-
debugger;
209208
test.markers().forEach(marker => {
210209
verify.indentationAtPositionIs(marker.fileName, marker.position, marker.data.indent, ts.IndentStyle.Smart, marker.data.baseIndentSize);
211210
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
//// (function(){
4+
//// var A;
5+
//// A/*1*/
6+
//// .a = function() { };
7+
//// })();
8+
9+
function navExact(name: string, kind: string) {
10+
return;
11+
}
12+
13+
verify.navigationTree(
14+
{
15+
"text": "<global>",
16+
"kind": "script",
17+
"childItems": [
18+
{
19+
"text": "<function>",
20+
"kind": "function",
21+
"childItems": [
22+
{
23+
"text": "A",
24+
"kind": "var"
25+
},
26+
{
27+
"text": "A.a",
28+
"kind": "function"
29+
}
30+
]
31+
}
32+
]
33+
});

0 commit comments

Comments
 (0)