* Fixes #922 Pass file contents to go-outline * Use fork of go-outline * Fixing broken test * If test files are dirty, dont run tests
This commit is contained in:
Родитель
217446dff8
Коммит
a5700fa3f7
|
@ -38,7 +38,7 @@ install:
|
|||
- go get -u -v github.com/rogpeppe/godef
|
||||
- if [[ "$(go version)" =~ "go version go1.5" ]]; then echo hello; else go get -u -v github.com/zmb3/gogetdoc; fi
|
||||
- if [[ "$(go version)" =~ "go version go1.5" ]]; then echo cannot get golint; else go get -u -v github.com/golang/lint/golint; fi
|
||||
- go get -u -v github.com/lukehoban/go-outline
|
||||
- go get -u -v github.com/ramya-rao-a/go-outline
|
||||
- go get -u -v sourcegraph.com/sqs/goreturns
|
||||
- go get -u -v golang.org/x/tools/cmd/gorename
|
||||
- go get -u -v github.com/tpng/gopkgs
|
||||
|
|
|
@ -29,6 +29,10 @@ function checkActiveEditor(): vscode.TextEditor {
|
|||
vscode.window.showInformationMessage('Cannot generate unit tests. File in the editor is not a Go file.');
|
||||
return;
|
||||
}
|
||||
if (editor.document.isDirty) {
|
||||
vscode.window.showInformationMessage('File has unsaved changes. Save and try again.');
|
||||
return;
|
||||
}
|
||||
return editor;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ function getTools(goVersion: SemVersion): { [key: string]: string } {
|
|||
let tools: { [key: string]: string } = {
|
||||
'gocode': 'github.com/nsf/gocode',
|
||||
'gopkgs': 'github.com/tpng/gopkgs',
|
||||
'go-outline': 'github.com/lukehoban/go-outline',
|
||||
'go-outline': 'github.com/ramya-rao-a/go-outline',
|
||||
'go-symbols': 'github.com/acroca/go-symbols',
|
||||
'guru': 'golang.org/x/tools/cmd/guru',
|
||||
'gorename': 'golang.org/x/tools/cmd/gorename',
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
'use strict';
|
||||
|
||||
import vscode = require('vscode');
|
||||
import { byteOffsetAt, getBinPath } from './util';
|
||||
import { byteOffsetAt, getBinPath, getFileArchive } from './util';
|
||||
import cp = require('child_process');
|
||||
import { promptForMissingTool } from './goInstallTools';
|
||||
|
||||
|
@ -125,8 +125,7 @@ function getTagsAndOptions(config: GoTagsConfig, commandArgs: GoTagsConfig): The
|
|||
function runGomodifytags(args: string[]) {
|
||||
let gomodifytags = getBinPath('gomodifytags');
|
||||
let editor = vscode.window.activeTextEditor;
|
||||
let fileContents = editor.document.getText();
|
||||
let input = editor.document.fileName + '\n' + Buffer.byteLength(fileContents, 'utf8') + '\n' + fileContents;
|
||||
let input = getFileArchive(editor.document);
|
||||
let p = cp.execFile(gomodifytags, args, (err, stdout, stderr) => {
|
||||
if (err && (<any>err).code === 'ENOENT') {
|
||||
promptForMissingTool('gomodifytags');
|
||||
|
|
|
@ -8,10 +8,10 @@
|
|||
import vscode = require('vscode');
|
||||
import cp = require('child_process');
|
||||
import path = require('path');
|
||||
import { getBinPath, sendTelemetryEvent } from './util';
|
||||
import { getBinPath, getFileArchive } from './util';
|
||||
import { promptForMissingTool, promptForUpdatingTool } from './goInstallTools';
|
||||
|
||||
// Keep in sync with https://github.com/lukehoban/go-outline
|
||||
// Keep in sync with https://github.com/ramya-rao-a/go-outline
|
||||
export interface GoOutlineRange {
|
||||
start: number;
|
||||
end: number;
|
||||
|
@ -30,8 +30,20 @@ export interface GoOutlineDeclaration {
|
|||
}
|
||||
|
||||
export interface GoOutlineOptions {
|
||||
/**
|
||||
* Path of the file for which outline is needed
|
||||
*/
|
||||
fileName: string;
|
||||
|
||||
/**
|
||||
* If true, then the file will be parsed only till imports are collected
|
||||
*/
|
||||
importsOnly?: boolean;
|
||||
|
||||
/**
|
||||
* Document to be parsed. If not provided, saved contents of the given fileName is used
|
||||
*/
|
||||
document?: vscode.TextDocument;
|
||||
}
|
||||
|
||||
export function documentSymbols(options: GoOutlineOptions): Promise<GoOutlineDeclaration[]> {
|
||||
|
@ -41,15 +53,24 @@ export function documentSymbols(options: GoOutlineOptions): Promise<GoOutlineDec
|
|||
if (options.importsOnly) {
|
||||
gooutlineFlags.push('-imports-only');
|
||||
}
|
||||
if (options.document) {
|
||||
gooutlineFlags.push('-modified');
|
||||
}
|
||||
// Spawn `go-outline` process
|
||||
let p = cp.execFile(gooutline, gooutlineFlags, {}, (err, stdout, stderr) => {
|
||||
try {
|
||||
if (err && (<any>err).code === 'ENOENT') {
|
||||
promptForMissingTool('go-outline');
|
||||
}
|
||||
if (stderr && stderr.startsWith('flag provided but not defined: -imports-only')) {
|
||||
if (stderr && stderr.startsWith('flag provided but not defined: ')) {
|
||||
promptForUpdatingTool('go-outline');
|
||||
options.importsOnly = false;
|
||||
if (stderr.startsWith('flag provided but not defined: -imports-only')) {
|
||||
options.importsOnly = false;
|
||||
}
|
||||
if (stderr.startsWith('flag provided but not defined: -modified')) {
|
||||
options.document = null;
|
||||
}
|
||||
|
||||
return documentSymbols(options).then(results => {
|
||||
return resolve(results);
|
||||
});
|
||||
|
@ -62,6 +83,9 @@ export function documentSymbols(options: GoOutlineOptions): Promise<GoOutlineDec
|
|||
reject(e);
|
||||
}
|
||||
});
|
||||
if (options.document) {
|
||||
p.stdin.end(getFileArchive(options.document));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -78,7 +102,6 @@ export class GoDocumentSymbolProvider implements vscode.DocumentSymbolProvider {
|
|||
private convertToCodeSymbols(document: vscode.TextDocument, decls: GoOutlineDeclaration[], symbols: vscode.SymbolInformation[], containerName: string): void {
|
||||
let gotoSymbolConfig = vscode.workspace.getConfiguration('go')['gotoSymbol'];
|
||||
let includeImports = gotoSymbolConfig ? gotoSymbolConfig['includeImports'] : false;
|
||||
sendTelemetryEvent('file-symbols', { includeImports: includeImports + '' });
|
||||
decls.forEach(decl => {
|
||||
if (!includeImports && decl.type === 'import') return;
|
||||
let label = decl.label;
|
||||
|
@ -104,7 +127,7 @@ export class GoDocumentSymbolProvider implements vscode.DocumentSymbolProvider {
|
|||
}
|
||||
|
||||
public provideDocumentSymbols(document: vscode.TextDocument, token: vscode.CancellationToken): Thenable<vscode.SymbolInformation[]> {
|
||||
let options = { fileName: document.fileName };
|
||||
let options = { fileName: document.fileName, document: document };
|
||||
return documentSymbols(options).then(decls => {
|
||||
let symbols: vscode.SymbolInformation[] = [];
|
||||
this.convertToCodeSymbols(document, decls, symbols, '');
|
||||
|
|
|
@ -65,6 +65,10 @@ export function testAtCursor(goConfig: vscode.WorkspaceConfiguration, args: any)
|
|||
vscode.window.showInformationMessage('No tests found. Current file is not a test file.');
|
||||
return;
|
||||
}
|
||||
if (editor.document.isDirty) {
|
||||
vscode.window.showInformationMessage('File has unsaved changes. Save and try again.');
|
||||
return;
|
||||
}
|
||||
getTestFunctions(editor.document).then(testFunctions => {
|
||||
let testFunction: vscode.SymbolInformation;
|
||||
// Find any test function containing the cursor.
|
||||
|
|
|
@ -281,3 +281,8 @@ export function getCurrentGoWorkspaceFromGOPATH(currentFileDirPath: string): str
|
|||
}
|
||||
return currentWorkspace;
|
||||
}
|
||||
|
||||
export function getFileArchive(document: vscode.TextDocument): string {
|
||||
let fileContents = document.getText();
|
||||
return document.fileName + '\n' + Buffer.byteLength(fileContents, 'utf8') + '\n' + fileContents;
|
||||
}
|
|
@ -665,7 +665,7 @@ It returns the number of bytes written and any write error encountered.
|
|||
// will fail and will have to be replaced with any other go project with vendor packages
|
||||
|
||||
let vendorSupportPromise = isVendorSupported();
|
||||
let filePath = path.join(process.env['GOPATH'], 'src', 'github.com', 'lukehoban', 'go-outline', 'main.go');
|
||||
let filePath = path.join(process.env['GOPATH'], 'src', 'github.com', 'ramya-rao-a', 'go-outline', 'main.go');
|
||||
let vendorPkgs = [
|
||||
'github.com/rogpeppe/godef/vendor/9fans.net/go/acme',
|
||||
'github.com/rogpeppe/godef/vendor/9fans.net/go/plan9',
|
||||
|
|
Загрузка…
Ссылка в новой задаче