^ outline to include constant & interface (#2973)
diff --git a/src/goOutline.ts b/src/goOutline.ts
index b81a743..f9e1c2b 100644
--- a/src/goOutline.ts
+++ b/src/goOutline.ts
@@ -116,9 +116,11 @@
'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(
@@ -151,8 +153,10 @@
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(
diff --git a/test/fixtures/outlineTest/test.go b/test/fixtures/outlineTest/test.go
index 9cf1ab6..14bf181 100644
--- a/test/fixtures/outlineTest/test.go
+++ b/test/fixtures/outlineTest/test.go
@@ -6,6 +6,8 @@
var _ string = "foobar"
+// const constFoo = "constBar"
+
func print(txt string) {
fmt.Println(txt)
}
@@ -16,3 +18,8 @@
type foo struct {
bar int
}
+
+type circle interface {
+ radius float64
+}
+
diff --git a/test/integration/extension.test.ts b/test/integration/extension.test.ts
index 13999de..1c36c5c 100644
--- a/test/integration/extension.test.ts
+++ b/test/integration/extension.test.ts
@@ -507,6 +507,7 @@
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);
@@ -514,6 +515,8 @@
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);
});