-
Notifications
You must be signed in to change notification settings - Fork 199
/
boot-sts-adapter.ts
60 lines (50 loc) · 2.1 KB
/
boot-sts-adapter.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import {StsAdapter, HighlightParams} from '@pivotal-tools/atom-languageclient-commons';
import {Convert} from 'atom-languageclient';
import { Range, CodeLens } from 'vscode-languageserver-protocol';
import {TextEditor, DecorationOptions } from 'atom';
const BOOT_HINT_GUTTER_NAME = 'boot-hint-gutter';
const DECORATION_OPTIONS: DecorationOptions = {
type: 'highlight',
class: 'boot-hint',
gutterName: BOOT_HINT_GUTTER_NAME
};
export class BootStsAdapter extends StsAdapter {
constructor() {
super();
}
onHighlight(params: HighlightParams) {
this.findEditors(params.doc.uri).forEach(editor => this.markHintsForEditor(editor, params.codeLenses));
}
private markHintsForEditor(editor: TextEditor, codeLenses: CodeLens[]) {
editor.getDecorations(DECORATION_OPTIONS).map(decoration => decoration.getMarker()).forEach(m => m.destroy());
const ranges = codeLenses.map(cl => cl.range);
if (Array.isArray(ranges)) {
ranges.forEach(range => this.createHintMarker(editor, range));
}
// const gutter = editor.gutterWithName(BOOT_HINT_GUTTER_NAME);
// if (gutter) {
// if (!ranges || !ranges.length) {
// gutter.hide();
// } else if (!gutter.isVisible()) {
// gutter.show();
// }
// }
}
private createHintMarker(editor: TextEditor, range: Range) {
// Create marker model
const marker = editor.markBufferRange(Convert.lsRangeToAtomRange(range));
// Marker around the text in the editor
editor.decorateMarker(marker, DECORATION_OPTIONS);
// Marker in the diagnostic gutter
// let gutter = editor.gutterWithName(BOOT_HINT_GUTTER_NAME);
// if (!gutter) {
// gutter = editor.addGutter({
// name: BOOT_HINT_GUTTER_NAME,
// visible: false,
// });
// }
// const iconElement = document.createElement('span');
// iconElement.setAttribute('class', 'gutter-boot-hint');
// gutter.decorateMarker(marker, {item: iconElement});
}
}