-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathclojureHover.ts
31 lines (24 loc) · 1.22 KB
/
clojureHover.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import * as vscode from 'vscode';
import { cljConnection } from './cljConnection';
import { cljParser } from './cljParser';
import { nreplClient } from './nreplClient';
export class ClojureHoverProvider implements vscode.HoverProvider {
provideHover(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Thenable<vscode.Hover> {
if (!cljConnection.isConnected())
return Promise.reject('No nREPL connected.');
let wordRange = document.getWordRangeAtPosition(position);
if (wordRange === undefined)
return Promise.resolve(new vscode.Hover('Docstring not found'));
let currentWord: string;
currentWord = document.lineAt(position.line).text.slice(wordRange.start.character, wordRange.end.character);
const ns = cljParser.getNamespace(document.getText());
return cljConnection.sessionForFilename(document.fileName).then(session => {
return nreplClient.info(currentWord, ns, session.id).then(info => {
if (info.doc) {
return Promise.resolve(new vscode.Hover(info.doc));
}
return Promise.reject(undefined);
});
});
}
}