Skip to content

Commit

Permalink
remove hack (#5587)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkslanc authored Jun 12, 2024
1 parent ecc5f67 commit 06fd974
Showing 1 changed file with 0 additions and 89 deletions.
89 changes: 0 additions & 89 deletions demo/kitchen-sink/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,95 +111,6 @@ function loadLanguageProvider(editor) {
});
window.languageProvider = languageProvider;
languageProvider.registerEditor(editor);
// hack to replace tooltip implementation from ace-linters with hover tooltip
// can be removed when ace-linters is updated to use MarkerGroup and HoverTooltip
if (languageProvider.$hoverTooltip)
editor.off("mousemove", languageProvider.$hoverTooltip.onMouseMove);
languageProvider.$messageController.$worker.addEventListener("message", function(e) {
var id = e.data.sessionId.split(".")[0];
var session = languageProvider.$getSessionLanguageProvider({id: id})?.session;
if (e.data.type == 6) {
// annotation message
e.stopPropagation();
if (session) {
showAnnotations(session, e.data.value);
}
} else if (e.data.type == 14) {
// highlights message
if (session) showOccurrenceMarkers(session, e.data.value);
}
}, true);
function showOccurrenceMarkers(session, positions) {
if (!session.state.occurrenceMarkers) {
session.state.occurrenceMarkers = new MarkerGroup(session);
}
session.state.occurrenceMarkers.setMarkers(positions.map(function(el) {
var r = el.range;
return {
range: new Range(r.start.line, r.start.character, r.end.line, r.end.character),
// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#documentHighlightKind
className: el.kind == 2
? "language_highlight_read"
: el.kind == 3
? "language_highlight_write"
: "language_highlight_text"
};
}));
}
function showAnnotations(session, diagnostics) {
session.clearAnnotations();
let annotations = diagnostics.map((el) => {
return {
row: el.range.start.line,
column: el.range.start.character,
text: el.message,
type: el.severity === 1 ? "error" : el.severity === 2 ? "warning" : "info"
};
});
if (annotations && annotations.length > 0) {
session.setAnnotations(annotations);
}

if (!session.state) session.state = {}
if (!session.state.diagnosticMarkers) {
session.state.diagnosticMarkers = new MarkerGroup(session);
}
session.state.diagnosticMarkers.setMarkers(diagnostics.map(function(el) {
var r = el.range;
return {
range: new Range(r.start.line, r.start.character, r.end.line, r.end.character),
tooltipText: el.message,
className: "language_highlight_error"
};
}));
};

docTooltip.setDataProvider(function(e, editor) {
let session = editor.session;
let docPos = e.getDocumentPosition();

languageProvider.doHover(session, docPos, function(hover) {
var errorMarker = session.state?.diagnosticMarkers.getMarkerAtPosition(docPos);

if (!errorMarker && !hover?.content) return;

var range = hover?.range || errorMarker?.range;
range = range ? Range.fromPoints(range.start, range.end) : session.getWordRange(docPos.row, docPos.column);
var hoverNode = hover && dom.buildDom(["div", {}]);
if (hoverNode) {
// todo render markdown using ace markdown mode
hoverNode.innerHTML = languageProvider.getTooltipText(hover);
};

var domNode = dom.buildDom(["div", {},
errorMarker && ["div", {}, errorMarker.tooltipText.trim()],
hoverNode
]);
docTooltip.showForRange(editor, range, domNode, e);
});
});

docTooltip.addToEditor(editor)
});
}

Expand Down

0 comments on commit 06fd974

Please sign in to comment.