Skip to content

Commit

Permalink
Merge branch 'hover' of https://github.com/abarisain/vscode-go into a…
Browse files Browse the repository at this point in the history
…barisain-hover
  • Loading branch information
lukehoban committed Aug 16, 2016
2 parents 1c5f87f + 97da99d commit 5de65a3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
5 changes: 4 additions & 1 deletion src/goDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ export function definitionLocation(document: vscode.TextDocument, position: vsco
break;
}
}
definitionInformation.doc = doc;

if (doc != '') {
definitionInformation.doc = doc;
}
return resolve(definitionInformation);
});
} catch (e) {
Expand Down
9 changes: 7 additions & 2 deletions src/goExtraInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { definitionLocation } from './goDeclaration';

export class GoHoverProvider implements HoverProvider {
public provideHover(document: TextDocument, position: Position, token: CancellationToken): Thenable<Hover> {
return definitionLocation(document, position, false).then(definitionInfo => {
return definitionLocation(document, position, true).then(definitionInfo => {
if (definitionInfo == null) return null;
let lines = definitionInfo.lines;
lines = lines.map(line => {
Expand All @@ -28,7 +28,12 @@ export class GoHoverProvider implements HoverProvider {
} else {
text = lines[0];
}
let hover = new Hover({ language: 'go', value: text });
let hoverTexts = [];
if (definitionInfo.doc != null) {
hoverTexts.push({ language: null, value: definitionInfo.doc});
}
hoverTexts.push({ language: 'go', value: text});
let hover = new Hover(hoverTexts);
return hover;
});
}
Expand Down
26 changes: 18 additions & 8 deletions test/go.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,29 @@ suite('Go Extension Tests', () => {

test('Test Hover Provider', (done) => {
let provider = new GoHoverProvider();
let testCases: [vscode.Position, string][] = [
let printlnDoc = `Println formats using the default formats for its operands and writes to
standard output. Spaces are always added between operands and a newline
is appended. It returns the number of bytes written and any write error
encountered.
`
let testCases: [vscode.Position, string, string][] = [
// [new vscode.Position(3,3), '/usr/local/go/src/fmt'],
[new vscode.Position(9, 6), 'main func()'],
[new vscode.Position(7, 2), 'import (fmt "fmt")'],
[new vscode.Position(7, 6), 'Println func(a ...interface{}) (n int, err error)'],
[new vscode.Position(10, 3), 'print func(txt string)']
[new vscode.Position(9, 6), 'main func()', null],
[new vscode.Position(7, 2), 'import (fmt "fmt")', null],
[new vscode.Position(7, 6), 'Println func(a ...interface{}) (n int, err error)', printlnDoc],
[new vscode.Position(10, 3), 'print func(txt string)', null]
];
let uri = vscode.Uri.file(path.join(fixturePath, 'test.go'));
vscode.workspace.openTextDocument(uri).then((textDocument) => {
let promises = testCases.map(([position, expected]) =>
let promises = testCases.map(([position, expectedSignature, expectedDocumentation]) =>
provider.provideHover(textDocument, position, null).then(res => {
assert.equal(res.contents.length, 1);
assert.equal(expected, (<{ language: string; value: string }>res.contents[0]).value);
if (expectedDocumentation == null) {
assert.equal(res.contents.length, 1);
} else {
assert.equal(res.contents.length, 2);
assert.equal(expectedDocumentation, (<{ language: string; value: string }>res.contents[0]).value);
}
assert.equal(expectedSignature, (<{ language: string; value: string }>res.contents[res.contents.length-1]).value);
})
);
return Promise.all(promises);
Expand Down

0 comments on commit 5de65a3

Please sign in to comment.