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

Commit

Permalink
Address PR feedback and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ragurney committed Aug 31, 2018
1 parent 7068517 commit 91909a1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/goOutline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class GoDocumentSymbolProvider implements vscode.DocumentSymbolProvider {
symbols: vscode.SymbolInformation[],
containerName: string,
byteOffsetToDocumentOffset: (byteOffset: number) => number): void {
const ignoredSymbols = ['_'];

let gotoSymbolConfig = vscode.workspace.getConfiguration('go', document.uri)['gotoSymbol'];
let includeImports = gotoSymbolConfig ? gotoSymbolConfig['includeImports'] : false;

Expand All @@ -119,7 +119,7 @@ export class GoDocumentSymbolProvider implements vscode.DocumentSymbolProvider {

let label = decl.label;

if (ignoredSymbols.indexOf(label) !== -1 && decl.type === 'variable') return;
if (label === '_' && decl.type === 'variable') return;

if (decl.receiverType) {
label = '(' + decl.receiverType + ').' + label;
Expand Down
14 changes: 14 additions & 0 deletions test/fixtures/outlineTest/test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import (
"fmt"
)

var _ string = "foobar"

func print(txt string) {
fmt.Println(txt)
}
func main() {
print("Hello")
}
28 changes: 25 additions & 3 deletions test/go.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { getEditsFromUnifiedDiffStr, getEdits } from '../src/diffUtils';
import jsDiff = require('diff');
import { testCurrentFile } from '../src/goTest';
import { getBinPath, getGoVersion, isVendorSupported } from '../src/util';
import { documentSymbols } from '../src/goOutline';
import { documentSymbols, GoDocumentSymbolProvider } from '../src/goOutline';
import { listPackages, getTextEditForAddImport } from '../src/goImport';
import { generateTestCurrentFile, generateTestCurrentPackage, generateTestCurrentFunction } from '../src/goGenerateTests';
import { getAllPackages } from '../src/goPackages';
Expand Down Expand Up @@ -76,6 +76,7 @@ suite('Go Extension Tests', () => {
fs.copySync(path.join(fixtureSourcePath, 'fillStruct', 'input_2.go'), path.join(fixturePath, 'fillStruct', 'input_2.go'));
fs.copySync(path.join(fixtureSourcePath, 'fillStruct', 'golden_2.go'), path.join(fixturePath, 'fillStruct', 'golden_2.go'));
fs.copySync(path.join(fixtureSourcePath, 'fillStruct', 'input_2.go'), path.join(fixturePath, 'fillStruct', 'input_3.go'));
fs.copySync(path.join(fixtureSourcePath, 'outlineTest', 'test.go'), path.join(fixturePath, 'outlineTest', 'test.go'));
});

suiteTeardown(() => {
Expand Down Expand Up @@ -522,7 +523,7 @@ It returns the number of bytes written and any write error encountered.
});

test('Test Outline', (done) => {
let filePath = path.join(fixturePath, 'test.go');
let filePath = path.join(fixturePath, 'outlineTest', 'test.go');
let options = { fileName: filePath };
documentSymbols(options, null).then(outlines => {
let packageOutline = outlines[0];
Expand All @@ -540,7 +541,7 @@ It returns the number of bytes written and any write error encountered.
});

test('Test Outline imports only', (done) => {
let filePath = path.join(fixturePath, 'test.go');
let filePath = path.join(fixturePath, 'outlineTest', 'test.go');
let options = { fileName: filePath, importsOnly: true };
documentSymbols(options, null).then(outlines => {
let packageOutline = outlines[0];
Expand All @@ -557,6 +558,27 @@ It returns the number of bytes written and any write error encountered.
}, done);
});

test('Test Outline document symbols', (done) => {
let uri = vscode.Uri.file(path.join(fixturePath, 'outlineTest', 'test.go'));
vscode.workspace.openTextDocument(uri).then(document => {
new GoDocumentSymbolProvider().provideDocumentSymbols(document, null).then(symbols => {
let groupedSymbolNames = symbols.reduce(function (map, symbol) {
map[symbol.kind] = (map[symbol.kind] || []).concat([symbol.name]);
return map;
}, {});

let packageNames = groupedSymbolNames[vscode.SymbolKind.Package];
let variableNames = groupedSymbolNames[vscode.SymbolKind.Variable];
let functionNames = groupedSymbolNames[vscode.SymbolKind.Function];

assert.equal(packageNames[0], 'main');
assert.equal(variableNames, undefined);
assert.equal(functionNames[0], 'print');
assert.equal(functionNames[1], 'main');
});
}).then(() => done(), done);
});

test('Test listPackages', (done) => {
let uri = vscode.Uri.file(path.join(fixturePath, 'test.go'));
vscode.workspace.openTextDocument(uri).then(document => {
Expand Down

0 comments on commit 91909a1

Please sign in to comment.