Skip to content

Commit

Permalink
🐛 Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 committed Jul 12, 2020
1 parent 5dc5354 commit 19d213b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
4 changes: 2 additions & 2 deletions example/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ const html = {
const js = {
serverUri: 'ws://localhost:3001/javascript',
languageId: 'javascript',
rootUri: `file://C:/Users/mespi/Projects/lsp-codemirror/example/example-project`,
documentUri: `file://C:/Users/mespi/Projects/lsp-codemirror/example/example-project/source.js`,
rootUri: `file:///${path.join(__dirname,'example-project')}`,
documentUri: `file:///${path.join(__dirname,'example-project/source.js')}`,
documentText: () => jsEditor.getValue(),
};

Expand Down
2 changes: 1 addition & 1 deletion example/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ new rpcWS({
languageServers:{
javascript:[
'node',
'C:/Users/mespi/Projects/Graviton-App/plugins/js-ts-langserver/wp/d.js'
'./node_modules/javascript-typescript-langserver/lib/language-server-stdio.js',
],
html:[
'node',
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lsp-codemirror",
"version": "0.1.2",
"version": "0.1.3",
"description": "LSP client for CodeMirror",
"main": "lib/index.js",
"module": "lib/index.js",
Expand All @@ -24,7 +24,7 @@
"languageserver",
"codemirror"
],
"repository": "github:marc2332/lsp-codemirror/",
"repository": "github:marc2332/lsp-codemirror",
"peerDependencies": {
"codemirror": "^5.55.0"
},
Expand Down
21 changes: 16 additions & 5 deletions src/codemirror-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ class CodeMirrorAdapter extends IEditorAdapter<CodeMirror.Editor> {

this._addListeners();
}


public handleMouseLeave(ev: MouseEvent) {
this._removeHover();
this._removeTooltip();
}

public handleMouseOver(ev: MouseEvent) {
if (this.isShowingContextMenu || !this._isEventInsideVisible(ev) || !this._isEventOnCharacter(ev)) {
if (!this._isEventInsideVisible(ev) || !this._isEventOnCharacter(ev)) {
return;
}

Expand Down Expand Up @@ -274,10 +279,9 @@ class CodeMirrorAdapter extends IEditorAdapter<CodeMirror.Editor> {
this._removeHover();
this._removeTooltip();
// Show-hint addon doesn't remove itself. This could remove other uses in the project
document.querySelectorAll('.CodeMirror-hints').forEach((e) => e.remove());
this.cm.getWrapperElement().getElementsByClassName('CodeMirror-hints').forEach((e) => e.remove());
this.editor.off('change', this.editorListeners.change);
this.editor.off('cursorActivity', this.editorListeners.cursorActivity);
this.editor.off('cursorActivity', this.editorListeners.cursorActivity);
this.editor.getWrapperElement().removeEventListener('mousemove', this.editorListeners.mouseover);
this.editor.getWrapperElement().removeEventListener('contextmenu', this.editorListeners.contextmenu);
Object.keys(this.connectionListeners).forEach((key) => {
Expand Down Expand Up @@ -307,6 +311,11 @@ class CodeMirrorAdapter extends IEditorAdapter<CodeMirror.Editor> {
this.connection.on(key as any, this.connectionListeners[key]);
});

const mouseLeaveListener = this.handleMouseLeave.bind(this);
this.editor.getWrapperElement().addEventListener('mouseleave', mouseLeaveListener);
this.editorListeners.mouseleave = mouseLeaveListener;


const mouseOverListener = this.handleMouseOver.bind(this);
this.editor.getWrapperElement().addEventListener('mousemove', mouseOverListener);
this.editorListeners.mouseover = mouseOverListener;
Expand Down Expand Up @@ -507,7 +516,7 @@ class CodeMirrorAdapter extends IEditorAdapter<CodeMirror.Editor> {
this.tooltip.style.left = `${coords.x}px`;
this.tooltip.style.top = `${top}px`;
this.tooltip.appendChild(el);
this.editor.getWrapperElement().appendChild(this.tooltip);
document.body.appendChild(this.tooltip);


// Measure and reposition after rendering first version
Expand All @@ -518,6 +527,8 @@ class CodeMirrorAdapter extends IEditorAdapter<CodeMirror.Editor> {
this.tooltip.style.left = `${coords.x}px`;
this.tooltip.style.top = `${top}px`;
});

this.isShowingContextMenu = true
}

private _removeTooltip() {
Expand Down
4 changes: 2 additions & 2 deletions src/codemirror-lsp.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
}

.CodeMirror-lsp-tooltip {
position: fixed;
position: absolute;
font-size: 12px;
background: white;
border: 1px solid darkgray;
padding: 4px 6px;
z-index: 2;
z-index: 3;
border-radius: 3px;
max-width: 200px;
}
Expand Down

0 comments on commit 19d213b

Please sign in to comment.