11// @ts -check
22/// <reference path="../typings/atom-ide.d.ts"/>
33
4- import {
5- CompositeDisposable ,
6- Disposable ,
7- Range ,
8- Point ,
9- TextEditor ,
10- CursorPositionChangedEvent ,
11- CommandEvent ,
12- } from "atom"
4+ import { CompositeDisposable , Disposable , Range , Point , TextEditor , CursorPositionChangedEventommandEvent } from "atom"
135import type { DatatipProvider } from "atom-ide-base"
6+ import { ViewContainer } from "atom-ide-base/commons-ui/float-pane/ViewContainer"
7+ import { getDocumentationHtml } from "atom-ide-base/commons-ui/float-pane/HTMLView"
8+ import { getSnippetHtml } from "atom-ide-base/commons-ui/float-pane/SnippetView"
9+
1410import { ProviderRegistry } from "atom-ide-base/commons-atom/ProviderRegistry"
15- import { DataTipView } from "./datatip-view"
1611
1712export class DataTipManager {
1813 constructor ( ) {
@@ -361,21 +356,37 @@ export class DataTipManager {
361356 this . currentMarkerRange = datatip . range
362357
363358 if ( datatip . component ) {
364- const dataTipView = new DataTipView ( { component : datatip . component } )
359+ const dataTipView = new ViewContainer ( {
360+ component : {
361+ element : datatip . component ,
362+ containerClassName : "datatip-container" ,
363+ contentClassName : "datatip-content" ,
364+ } ,
365+ } )
365366 this . dataTipMarkerDisposables = this . mountDataTipWithMarker ( editor , datatip . range , position , dataTipView )
366367 } else if ( datatip . markedStrings . length > 0 ) {
367368 const grammar = editor . getGrammar ( ) . scopeName . toLowerCase ( )
368- const snippetHtml = await this . getSnippetHtml (
369+ const snippetHtml = await getSnippetHtml (
369370 datatip . markedStrings . filter ( ( t ) => t . type === "snippet" ) . map ( ( t ) => t . value ) ,
370- grammar
371+ grammar ,
372+ this . renderer
371373 )
372- const documentationHtml = await this . getDocumentationHtml (
374+ const documentationHtml = await getDocumentationHtml (
373375 datatip . markedStrings . filter ( ( t ) => t . type === "markdown" ) . map ( ( t ) => t . value ) ,
374- grammar
376+ grammar ,
377+ this . renderer
375378 )
376- const dataTipView = new DataTipView ( {
377- snippet : snippetHtml ,
378- html : documentationHtml ,
379+ const dataTipView = new ViewContainer ( {
380+ snippet : {
381+ element : snippetHtml ,
382+ containerClassName : "datatip-container" ,
383+ contentClassName : "datatip-snippet" ,
384+ } ,
385+ html : {
386+ element : documentationHtml ,
387+ containerClassName : "datatip-container" ,
388+ contentClassName : "datatip-marked" ,
389+ } ,
379390 } )
380391 this . dataTipMarkerDisposables = this . mountDataTipWithMarker ( editor , datatip . range , position , dataTipView )
381392 }
@@ -385,43 +396,6 @@ export class DataTipManager {
385396 }
386397 }
387398
388- /**
389- * converts a given code snippet into syntax formatted HTML
390- * @param {Array<String> } snippets the code snippet to be converted
391- * @param {String } grammarName the name of the grammar to be used for syntax highlighting
392- * @return {Promise<string> } a promise object to track the asynchronous operation
393- */
394- async getSnippetHtml ( snippets , grammarName ) {
395- if ( snippets !== undefined && snippets . length > 0 ) {
396- const regExpLSPPrefix = / ^ \( ( m e t h o d | p r o p e r t y | p a r a m e t e r | a l i a s ) \) \W /
397- const divElem = document . createElement ( "div" )
398- snippets . forEach ( ( snippet ) => {
399- const preElem = document . createElement ( "pre" )
400- const codeElem = document . createElement ( "code" )
401- snippet = snippet . replace ( / ^ \s * < ( \? | ! ) ( [ a - z A - Z ] + ) ? \s * / i, "" ) // remove any preamble from the line
402- codeElem . innerText = snippet . replace ( regExpLSPPrefix , "" )
403- preElem . appendChild ( codeElem )
404- divElem . appendChild ( preElem )
405- } )
406- return this . renderer . render ( divElem . outerHTML , grammarName )
407- }
408- return null
409- }
410-
411- /**
412- * convert the markdown documentation to HTML
413- * @param {Array<String> } markdownTexts the documentation text in markdown format to be converted
414- * @param {String } grammarName the default grammar used for embedded code samples
415- * @return {Promise<string> } a promise object to track the asynchronous operation
416- */
417- async getDocumentationHtml ( markdownTexts , grammarName ) {
418- if ( markdownTexts !== undefined && markdownTexts . length > 0 ) {
419- const markdownText = markdownTexts . join ( "\r\n" )
420- return this . renderer . render ( markdownText , grammarName )
421- }
422- return null
423- }
424-
425399 /**
426400 * mounts / displays a data tip view component at a specific position in a given Atom Text editor
427401 * @param {TextEditor } editor the Atom Text editor instance to host the data tip view
0 commit comments