Skip to content

Commit

Permalink
Merge pull request #47 from atom-ide-community/feat/iterate-datatip-p…
Browse files Browse the repository at this point in the history
…roviders

feat: prepare for diagnostic data tips
  • Loading branch information
appelgriebsch authored Jun 24, 2019
2 parents 62c6c1a + 9818b39 commit 5af5289
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 186 deletions.
61 changes: 33 additions & 28 deletions lib/datatip-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,34 +290,39 @@ module.exports = class DatatipManager {
*/
async showDataTip (editor, position, evt) {
try {
const provider = this.providerRegistry.getProviderForEditor(editor);
if (provider) {
const datatip = await provider.datatip(editor, position, evt);

if (!datatip) { this.unmountDataTip(); }
else {
// omit update of UI if the range is the same as the current one
if (this.currentMarkerRange != null && datatip.range.intersectsWith(this.currentMarkerRange)) { return; }
// make sure we are still on the same position
if (!datatip.range.containsPoint(position)) { return; }

// clear last data tip
this.unmountDataTip();

// store marker range
this.currentMarkerRange = datatip.range;

if (datatip.component){
const dataTipView = new DataTipView({ component: datatip.component });
this.dataTipMarkerDisposables = this.mountDataTipWithMarker(editor, datatip.range, position, dataTipView);
}
else if (datatip.markedStrings.length > 0) {
const grammar = editor.getGrammar().scopeName.toLowerCase();
const snippetHtml = await this.getSnippetHtml(datatip.markedStrings.filter(t => t.type === 'snippet').map(t => t.value), grammar);
const documentationHtml = await this.getDocumentationHtml(datatip.markedStrings.filter(t => t.type === 'markdown').map(t => t.value), grammar);
const dataTipView = new DataTipView({ snippet: snippetHtml, html: documentationHtml });
this.dataTipMarkerDisposables = this.mountDataTipWithMarker(editor, datatip.range, position, dataTipView);
}
let datatip = null;
for (const provider of this.providerRegistry.getAllProvidersForEditor(editor)) {
const providerTip = await provider.datatip(editor, position, evt);
if (providerTip) {
datatip = providerTip;
break;
}
}
if (!datatip) {
this.unmountDataTip();
}
else {
// omit update of UI if the range is the same as the current one
if (this.currentMarkerRange != null && datatip.range.intersectsWith(this.currentMarkerRange)) { return; }
// make sure we are still on the same position
if (!datatip.range.containsPoint(position)) { return; }

// clear last data tip
this.unmountDataTip();

// store marker range
this.currentMarkerRange = datatip.range;

if (datatip.component){
const dataTipView = new DataTipView({ component: datatip.component });
this.dataTipMarkerDisposables = this.mountDataTipWithMarker(editor, datatip.range, position, dataTipView);
}
else if (datatip.markedStrings.length > 0) {
const grammar = editor.getGrammar().scopeName.toLowerCase();
const snippetHtml = await this.getSnippetHtml(datatip.markedStrings.filter(t => t.type === 'snippet').map(t => t.value), grammar);
const documentationHtml = await this.getDocumentationHtml(datatip.markedStrings.filter(t => t.type === 'markdown').map(t => t.value), grammar);
const dataTipView = new DataTipView({ snippet: snippetHtml, html: documentationHtml });
this.dataTipMarkerDisposables = this.mountDataTipWithMarker(editor, datatip.range, position, dataTipView);
}
}
} catch (err) {
Expand Down
Loading

0 comments on commit 5af5289

Please sign in to comment.