Skip to content

Commit a40b016

Browse files
authored
Merge pull request #100 from atom-ide-community/atom-ide-base
2 parents a175dbd + cef003a commit a40b016

5 files changed

Lines changed: 41 additions & 61 deletions

File tree

lib/datatip-manager.js

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
import { CompositeDisposable, Disposable, Range, Point, TextEditor, CursorPositionChangedEventommandEvent } from "atom"
44
import type { DatatipProvider, MarkdownService } from "atom-ide-base"
55
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-
96
import { ProviderRegistry } from "atom-ide-base/commons-atom/ProviderRegistry"
107

118
export class DataTipManager {
@@ -77,23 +74,18 @@ export class DataTipManager {
7774
* only if the cursor is not moving for more than hoverTime the data tip functionality is triggered
7875
*/
7976
this.cursorMoveTimer = null
80-
/**
81-
* a reference to the markdown rendering service
82-
* @type {MarkdownService}
83-
*/
84-
this.renderer = null
8577

8678
/** 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]. */
8779
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" : ""
8883
}
8984

9085
/**
9186
* initialization routine retrieving a reference to the markdown service
92-
* @param {MarkdownService} renderer the markdown rendering service reference
9387
*/
94-
initialize(renderer) {
95-
this.renderer = renderer
96-
88+
initialize() {
9789
this.subscriptions.add(
9890
atom.workspace.observeTextEditors((editor) => {
9991
const disposable = this.watchEditor(editor)
@@ -357,36 +349,45 @@ export class DataTipManager {
357349
if (datatip.component) {
358350
const dataTipView = new ViewContainer({
359351
component: {
360-
element: datatip.component,
352+
component: datatip.component,
361353
containerClassName: "datatip-container",
362354
contentClassName: "datatip-content",
363355
},
356+
className: this.glowClass
364357
})
365358
this.dataTipMarkerDisposables = this.mountDataTipWithMarker(editor, datatip.range, position, dataTipView)
366359
} else if (datatip.markedStrings.length > 0) {
367360
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,
381377
containerClassName: "datatip-container",
382378
contentClassName: "datatip-snippet",
383-
},
384-
html: {
385-
element: documentationHtml,
379+
}
380+
}
381+
if (markdownData.length > 0) {
382+
markdown = {
383+
markdown: markdownData,
384+
grammarName: grammar,
386385
containerClassName: "datatip-container",
387386
contentClassName: "datatip-marked",
388-
},
389-
})
387+
}
388+
}
389+
390+
const dataTipView = new ViewContainer({ snippet, markdown, className: this.glowClass })
390391
this.dataTipMarkerDisposables = this.mountDataTipWithMarker(editor, datatip.range, position, dataTipView)
391392
}
392393
}

lib/main.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { CompositeDisposable } from "atom"
44
import { DataTipManager } from "./datatip-manager"
5-
import type { DatatipService, MarkdownService } from "atom-ide-base"
5+
import type { DatatipService } from "atom-ide-base"
66

77
/**
88
* the Atom IDE data tip plugin
@@ -19,11 +19,6 @@ let subscriptions
1919
* @type {DataTipManager}
2020
*/
2121
let datatipManager
22-
/**
23-
* a reference to the markdown rendering service
24-
* @type {MarkdownService}
25-
*/
26-
let renderer = null
2722

2823
/**
2924
* called by Atom when activating an extension
@@ -36,13 +31,13 @@ export async function activate(state) {
3631
subscriptions.add(datatipManager)
3732

3833
install_deps().then(() => {
39-
datatipManager.initialize(renderer)
34+
datatipManager.initialize()
4035
})
4136
}
4237

4338
async function install_deps() {
4439
// install package-deps if not loaded
45-
if (!(atom.packages.isPackageLoaded("atom-ide-markdown-service") && atom.packages.isPackageLoaded("busy-signal"))) {
40+
if (!(atom.packages.isPackageLoaded("busy-signal"))) {
4641
// Dynamic import https://mariusschulz.com/blog/dynamic-import-expressions-in-typescript
4742
await import("atom-package-deps").then((atom_package_deps) => {
4843
atom_package_deps.install("atom-ide-datatip")
@@ -69,14 +64,6 @@ export function provideDatatipService() {
6964
return datatipManager.datatipService
7065
}
7166

72-
/**
73-
* retrieves a reference to the markdown rendering service that should be used
74-
* @param {MarkdownService} markdownService the service for rendering markdown text
75-
*/
76-
export function consumeMarkdownRenderer(markdownService) {
77-
renderer = markdownService
78-
}
79-
8067
export const config = {
8168
showDataTipOnCursorMove: {
8269
title: 'Show datatip automatically on "cursor" stay',

package.json

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@
2727
"atom": ">=1.0.0 <2.0.0"
2828
},
2929
"package-deps": [
30-
"atom-ide-markdown-service",
3130
"busy-signal"
3231
],
3332
"dependencies": {
34-
"atom-ide-base": "^1.11.2",
33+
"atom-ide-base": "^2.0.0",
3534
"atom-package-deps": "^6.0.0"
3635
},
3736
"devDependencies": {
@@ -65,12 +64,5 @@
6564
"0.1.0": "provideDatatipService"
6665
}
6766
}
68-
},
69-
"consumedServices": {
70-
"markdown-renderer": {
71-
"versions": {
72-
"1.0.0": "consumeMarkdownRenderer"
73-
}
74-
}
7567
}
7668
}

pnpm-lock.yaml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

styles/atom-ide-datatips.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
// glow on hover
3131
transition: background-color 0.15s ease;
3232
&:hover {
33-
background-color: mix(@syntax-background-color, @syntax-selection-color, 50%);
33+
background-color: mix(@syntax-background-color, @syntax-selection-color, 95%);
3434
}
3535
}
3636

0 commit comments

Comments
 (0)