Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Differentiate between interfaces and structs in outline (#2114)
Browse files Browse the repository at this point in the history
* Differentiate between interface and struct

* Use regex to match structs

* Change to regex test

* Improved regex

* Stricter regex

* Added test case for struct outline

* Minimum 1 space needed between words
  • Loading branch information
karthikraobr authored and ramya-rao-a committed Nov 21, 2018
1 parent f26c88f commit f4a6c67
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/goOutline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ const goKindToCodeKind: { [key: string]: vscode.SymbolKind } = {
'import': vscode.SymbolKind.Namespace,
'variable': vscode.SymbolKind.Variable,
'type': vscode.SymbolKind.Interface,
'function': vscode.SymbolKind.Function
'function': vscode.SymbolKind.Function,
'struct': vscode.SymbolKind.Struct,
};


Expand All @@ -149,11 +150,17 @@ function convertToCodeSymbols(
label = '(' + decl.receiverType + ').' + label;
}


let range = null;
if (document && byteOffsetToDocumentOffset) {
let start = byteOffsetToDocumentOffset(decl.start - 1);
let end = byteOffsetToDocumentOffset(decl.end - 1);
range = new vscode.Range(document.positionAt(start), document.positionAt(end));
if (decl.type === 'type') {
let line = document.lineAt(document.positionAt(start));
let regex = new RegExp(`^\\s*type\\s+${decl.label}\\s+struct\\b`);
decl.type = regex.test(line.text) ? 'struct' : 'type';
}
}

let symbolInfo = new vscode.SymbolInformation(
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/outlineTest/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ func print(txt string) {
func main() {
print("Hello")
}

type foo struct {
bar int
}
4 changes: 3 additions & 1 deletion test/go.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,11 +602,13 @@ It returns the number of bytes written and any write error encountered.
let packageNames = groupedSymbolNames[vscode.SymbolKind.Package];
let variableNames = groupedSymbolNames[vscode.SymbolKind.Variable];
let functionNames = groupedSymbolNames[vscode.SymbolKind.Function];

let structs = groupedSymbolNames[vscode.SymbolKind.Struct];
assert.equal(packageNames[0], 'main');
assert.equal(variableNames, undefined);
assert.equal(functionNames[0], 'print');
assert.equal(functionNames[1], 'main');
assert.equal(structs.length, 1);
assert.equal(structs[0], 'foo');
});
}).then(() => done(), done);
});
Expand Down

0 comments on commit f4a6c67

Please sign in to comment.