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

Extra info now checks doc #424

Merged
merged 2 commits into from
Aug 16, 2016
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
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});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that passing this as a string will format in a slightly different way which matches what other extensions do: https://github.com/Microsoft/vscode/search?utf8=%E2%9C%93&q=%22new+Hover%22

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about that, didn't notice that there was a simple string constructor for this

}
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.
`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I really like how templates strings break indentation, but it does not destroy the file's column count that way

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