Skip to content

Commit

Permalink
Fix selectedRange sometimes not using the name token
Browse files Browse the repository at this point in the history
E.g. enum constructors, simple typedef fields...
The difference is only visible with VSCode 1.26, see microsoft/vscode#54857.
  • Loading branch information
Gama11 committed Jul 25, 2018
1 parent 87c2d06 commit d526c83
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
60 changes: 30 additions & 30 deletions cases/documentSymbols/Expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -704,11 +704,11 @@
"selectionRange": {
"start": {
"line": 75,
"character": 24
"character": 16
},
"end": {
"line": 75,
"character": 25
"character": 24
}
}
}
Expand Down Expand Up @@ -756,11 +756,11 @@
"selectionRange": {
"start": {
"line": 77,
"character": 16
"character": 15
},
"end": {
"line": 77,
"character": 17
"character": 16
}
}
},
Expand All @@ -781,11 +781,11 @@
"selectionRange": {
"start": {
"line": 77,
"character": 20
"character": 18
},
"end": {
"line": 77,
"character": 21
"character": 19
}
},
"children": [
Expand Down Expand Up @@ -858,11 +858,11 @@
"selectionRange": {
"start": {
"line": 83,
"character": 21
"character": 13
},
"end": {
"line": 83,
"character": 23
"character": 20
}
}
},
Expand Down Expand Up @@ -908,11 +908,11 @@
"selectionRange": {
"start": {
"line": 88,
"character": 24
"character": 15
},
"end": {
"line": 88,
"character": 25
"character": 24
}
}
},
Expand Down Expand Up @@ -1010,11 +1010,11 @@
"selectionRange": {
"start": {
"line": 96,
"character": 20
"character": 14
},
"end": {
"line": 96,
"character": 21
"character": 19
}
},
"children": [
Expand Down Expand Up @@ -1578,11 +1578,11 @@
"selectionRange": {
"start": {
"line": 141,
"character": 10
"character": 4
},
"end": {
"line": 141,
"character": 11
"character": 10
}
}
},
Expand All @@ -1603,11 +1603,11 @@
"selectionRange": {
"start": {
"line": 142,
"character": 11
"character": 4
},
"end": {
"line": 142,
"character": 12
"character": 11
}
}
}
Expand Down Expand Up @@ -1680,11 +1680,11 @@
"selectionRange": {
"start": {
"line": 148,
"character": 6
"character": 5
},
"end": {
"line": 148,
"character": 7
"character": 6
}
}
},
Expand All @@ -1705,11 +1705,11 @@
"selectionRange": {
"start": {
"line": 149,
"character": 5
"character": 4
},
"end": {
"line": 149,
"character": 6
"character": 5
}
}
}
Expand Down Expand Up @@ -1807,11 +1807,11 @@
"selectionRange": {
"start": {
"line": 155,
"character": 8
"character": 9
},
"end": {
"line": 155,
"character": 9
"character": 10
}
}
},
Expand Down Expand Up @@ -1884,11 +1884,11 @@
"selectionRange": {
"start": {
"line": 161,
"character": 6
"character": 5
},
"end": {
"line": 161,
"character": 7
"character": 6
}
}
},
Expand All @@ -1909,11 +1909,11 @@
"selectionRange": {
"start": {
"line": 162,
"character": 5
"character": 4
},
"end": {
"line": 162,
"character": 6
"character": 5
}
}
}
Expand Down Expand Up @@ -1961,11 +1961,11 @@
"selectionRange": {
"start": {
"line": 166,
"character": 5
"character": 4
},
"end": {
"line": 166,
"character": 6
"character": 5
}
}
},
Expand All @@ -1986,11 +1986,11 @@
"selectionRange": {
"start": {
"line": 168,
"character": 5
"character": 4
},
"end": {
"line": 168,
"character": 6
"character": 5
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/haxeLanguageServer/tokentree/DocumentSymbolsResolver.hx
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ class DocumentSymbolsResolver {
document.tokens.tree.filterCallback(function(token:TokenTree, depth:Int) {
stack.depth = depth;
function add(token:TokenTree, kind:SymbolKind, level:SymbolLevel, ?name:String, ?opensScope:Bool) {
if (name == null) {
name = token.getName();
}
if (name == null) {
return;
var nameToken = token.getNameToken();
if (nameToken == null && name != null) {
nameToken = token;
}
var selectedToken = token.access().firstChild().or(token);
if (selectedToken.inserted) {
if (nameToken == null || nameToken.inserted) {
return; // don't want to show `autoInsert` vars and similar
}
if (name == null) {
name = nameToken.getName();
}
if (opensScope == null) {
opensScope = true;
}
Expand All @@ -36,7 +36,7 @@ class DocumentSymbolsResolver {
detail: "",
kind: kind,
range: positionToRange(document.tokens.getTreePos(token)),
selectionRange: positionToRange(document.tokens.getPos(selectedToken))
selectionRange: positionToRange(document.tokens.getPos(nameToken))
};
if (token.isDeprecated()) {
symbol.deprecated = true;
Expand All @@ -46,7 +46,7 @@ class DocumentSymbolsResolver {

switch (token.tok) {
case Kwd(KwdClass):
var name = token.getName();
var name = token.getNameToken().getName();
if (name == null && token.isTypeMacroClass()) {
name = "<macro class>";
}
Expand Down

0 comments on commit d526c83

Please sign in to comment.