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

Differentiate between interfaces and structs in outline #2114

Merged
merged 9 commits into from
Nov 21, 2018
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