|
3 | 3 | import { CompositeDisposable, Disposable, Range, Point, TextEditor, CursorPositionChangedEventommandEvent } from "atom" |
4 | 4 | import type { DatatipProvider, MarkdownService } from "atom-ide-base" |
5 | 5 | import { ViewContainer } from "atom-ide-base/commons-ui/float-pane/ViewContainer" |
6 | | -import { getDocumentationHtml } from "atom-ide-base/commons-ui/float-pane/HTMLView" |
7 | | -import { getSnippetHtml } from "atom-ide-base/commons-ui/float-pane/SnippetView" |
8 | | - |
9 | 6 | import { ProviderRegistry } from "atom-ide-base/commons-atom/ProviderRegistry" |
10 | 7 |
|
11 | 8 | export class DataTipManager { |
@@ -77,23 +74,18 @@ export class DataTipManager { |
77 | 74 | * only if the cursor is not moving for more than hoverTime the data tip functionality is triggered |
78 | 75 | */ |
79 | 76 | this.cursorMoveTimer = null |
80 | | - /** |
81 | | - * a reference to the markdown rendering service |
82 | | - * @type {MarkdownService} |
83 | | - */ |
84 | | - this.renderer = null |
85 | 77 |
|
86 | 78 | /** The time that the mouse/cursor should hover/stay to show a datatip. Also specifies the time that the datatip is still shown when the mouse/cursor moves [ms]. */ |
87 | 79 | this.hoverTime = atom.config.get("atom-ide-datatip.hoverTime") |
| 80 | + |
| 81 | + // glow on hover |
| 82 | + this.glowClass = atom.config.get("atom-ide-datatip.glowOnHover") ? "datatip-glow" : "" |
88 | 83 | } |
89 | 84 |
|
90 | 85 | /** |
91 | 86 | * initialization routine retrieving a reference to the markdown service |
92 | | - * @param {MarkdownService} renderer the markdown rendering service reference |
93 | 87 | */ |
94 | | - initialize(renderer) { |
95 | | - this.renderer = renderer |
96 | | - |
| 88 | + initialize() { |
97 | 89 | this.subscriptions.add( |
98 | 90 | atom.workspace.observeTextEditors((editor) => { |
99 | 91 | const disposable = this.watchEditor(editor) |
@@ -357,36 +349,45 @@ export class DataTipManager { |
357 | 349 | if (datatip.component) { |
358 | 350 | const dataTipView = new ViewContainer({ |
359 | 351 | component: { |
360 | | - element: datatip.component, |
| 352 | + component: datatip.component, |
361 | 353 | containerClassName: "datatip-container", |
362 | 354 | contentClassName: "datatip-content", |
363 | 355 | }, |
| 356 | + className: this.glowClass |
364 | 357 | }) |
365 | 358 | this.dataTipMarkerDisposables = this.mountDataTipWithMarker(editor, datatip.range, position, dataTipView) |
366 | 359 | } else if (datatip.markedStrings.length > 0) { |
367 | 360 | const grammar = editor.getGrammar().scopeName.toLowerCase() |
368 | | - const snippetHtml = await getSnippetHtml( |
369 | | - datatip.markedStrings.filter((t) => t.type === "snippet").map((t) => t.value), |
370 | | - grammar, |
371 | | - this.renderer |
372 | | - ) |
373 | | - const documentationHtml = await getDocumentationHtml( |
374 | | - datatip.markedStrings.filter((t) => t.type === "markdown").map((t) => t.value), |
375 | | - grammar, |
376 | | - this.renderer |
377 | | - ) |
378 | | - const dataTipView = new ViewContainer({ |
379 | | - snippet: { |
380 | | - element: snippetHtml, |
| 361 | + |
| 362 | + let snippetData: string[] = [] |
| 363 | + let markdownData: string[] = [] |
| 364 | + for (const markedString of datatip.markedStrings) { |
| 365 | + if (markedString.type === "snippet") { |
| 366 | + snippetData.push(markedString.value) |
| 367 | + } else if (markedString.type === "markdown") { |
| 368 | + markdownData.push(markedString.value) |
| 369 | + } |
| 370 | + } |
| 371 | + |
| 372 | + let snippet, markdown = undefined |
| 373 | + if (snippetData.length > 0) { |
| 374 | + snippet = { |
| 375 | + snippet: snippetData, |
| 376 | + grammarName: grammar, |
381 | 377 | containerClassName: "datatip-container", |
382 | 378 | contentClassName: "datatip-snippet", |
383 | | - }, |
384 | | - html: { |
385 | | - element: documentationHtml, |
| 379 | + } |
| 380 | + } |
| 381 | + if (markdownData.length > 0) { |
| 382 | + markdown = { |
| 383 | + markdown: markdownData, |
| 384 | + grammarName: grammar, |
386 | 385 | containerClassName: "datatip-container", |
387 | 386 | contentClassName: "datatip-marked", |
388 | | - }, |
389 | | - }) |
| 387 | + } |
| 388 | + } |
| 389 | + |
| 390 | + const dataTipView = new ViewContainer({ snippet, markdown, className: this.glowClass }) |
390 | 391 | this.dataTipMarkerDisposables = this.mountDataTipWithMarker(editor, datatip.range, position, dataTipView) |
391 | 392 | } |
392 | 393 | } |
|
0 commit comments