diff --git a/src/goOutline.ts b/src/goOutline.ts index 6507886b1..8d607fba7 100644 --- a/src/goOutline.ts +++ b/src/goOutline.ts @@ -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, }; @@ -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( diff --git a/test/fixtures/outlineTest/test.go b/test/fixtures/outlineTest/test.go index e56664ce7..9cf1ab676 100644 --- a/test/fixtures/outlineTest/test.go +++ b/test/fixtures/outlineTest/test.go @@ -12,3 +12,7 @@ func print(txt string) { func main() { print("Hello") } + +type foo struct { + bar int +} diff --git a/test/go.test.ts b/test/go.test.ts index 350a17f9c..fafe691c1 100644 --- a/test/go.test.ts +++ b/test/go.test.ts @@ -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); });