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

^ outline to include constant & interface #2973

Merged
merged 5 commits into from
Jan 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/goOutline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ const goKindToCodeKind: { [key: string]: vscode.SymbolKind } = {
'package': vscode.SymbolKind.Package,
'import': vscode.SymbolKind.Namespace,
'variable': vscode.SymbolKind.Variable,
'type': vscode.SymbolKind.Interface,
'constant': vscode.SymbolKind.Constant,
'type': vscode.SymbolKind.TypeParameter,
'function': vscode.SymbolKind.Function,
'struct': vscode.SymbolKind.Struct,
'interface': vscode.SymbolKind.Interface,
};

function convertToCodeSymbols(
Expand Down Expand Up @@ -151,8 +153,10 @@ function convertToCodeSymbols(

if (decl.type === 'type') {
const line = document.lineAt(document.positionAt(start));
const regex = new RegExp(`^\\s*type\\s+${decl.label}\\s+struct\\b`);
decl.type = regex.test(line.text) ? 'struct' : 'type';
const regexStruct = new RegExp(`^\\s*type\\s+${decl.label}\\s+struct\\b`);
const regexInterface = new RegExp(`^\\s*type\\s+${decl.label}\\s+interface\\b`);
decl.type = regexStruct.test(line.text) ? 'struct' :
regexInterface.test(line.text) ? 'interface' : 'type';
}

const symbolInfo = new vscode.DocumentSymbol(
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/outlineTest/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (

var _ string = "foobar"

// const constFoo = "constBar"

func print(txt string) {
fmt.Println(txt)
}
Expand All @@ -16,3 +18,8 @@ func main() {
type foo struct {
bar int
}

type circle interface {
radius float64
}

3 changes: 3 additions & 0 deletions test/integration/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,13 +507,16 @@ It returns the number of bytes written and any write error encountered.
const variables = outlines[0].children.filter((x: any) => x.kind === vscode.SymbolKind.Variable);
const functions = outlines[0].children.filter((x: any) => x.kind === vscode.SymbolKind.Function);
const structs = outlines[0].children.filter((x: any) => x.kind === vscode.SymbolKind.Struct);
const interfaces = outlines[0].children.filter((x: any) => x.kind === vscode.SymbolKind.Interface);

assert.equal(packages[0].name, 'main');
assert.equal(variables.length, 0);
assert.equal(functions[0].name, 'print');
assert.equal(functions[1].name, 'main');
assert.equal(structs.length, 1);
assert.equal(structs[0].name, 'foo');
assert.equal(interfaces.length, 1);
assert.equal(interfaces[0].name, 'circle');
});
}).then(() => done(), done);
});
Expand Down