Skip to content
This repository has been archived by the owner on Jul 17, 2020. It is now read-only.

Commit

Permalink
cleanup. remove unnecessary variables
Browse files Browse the repository at this point in the history
  • Loading branch information
tststs committed Feb 26, 2017
1 parent 4564d6d commit 36127e0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 50 deletions.
2 changes: 1 addition & 1 deletion lib/atom-ternjs-manager.js
Expand Up @@ -278,7 +278,7 @@ class Manager {

if (packageConfig.options.inlineFnCompletion) {

type.queryType(editor, e.cursor);
this.client && type.queryType(editor, e);
}

emitter.emit('documentation-destroy-overlay');
Expand Down
23 changes: 5 additions & 18 deletions lib/atom-ternjs-type-view.js
@@ -1,32 +1,19 @@
'use babel';

import TernView from './atom-ternjs-view';
import packageConfig from './atom-ternjs-package-config';

class TypeView extends TernView {

createdCallback() {
initialize(model) {

this.addEventListener('click', () => {
super.initialize(model);

this.getModel().destroyOverlay();

}, false);

this.container = document.createElement('div');
this.appendChild(this.container);
this.addEventListener('click', model.destroyOverlay);
}

setData(data) {

if (packageConfig.options.inlineFnCompletionDocumentation) {

this.container.innerHTML = data.doc ? `${data.type}<br /><br />${data.doc}` : `${data.type}`;

return;
}
setData(type, documentation) {

this.container.innerHTML = data.type;
this.innerHTML = documentation ? `${type}<br /><br />${documentation}` : `${type}`;
}
}

Expand Down
47 changes: 18 additions & 29 deletions lib/atom-ternjs-type.js
Expand Up @@ -23,11 +23,10 @@ class Type {
this.view = null;
this.overlayDecoration = null;

this.scopeLost = true;
this.currentRange = null;
this.currentViewData = null;

this.destroyOverlayHandler = this.destroyOverlay.bind(this);
this.destroyOverlayListener = this.destroyOverlay.bind(this);
}

init() {
Expand All @@ -37,24 +36,24 @@ class Type {

atom.views.getView(atom.workspace).appendChild(this.view);

emitter.on('type-destroy-overlay', this.destroyOverlayHandler);
emitter.on('type-destroy-overlay', this.destroyOverlayListener);
}

setPosition() {

const editor = atom.workspace.getActiveTextEditor();

if (!editor) {
if (this.overlayDecoration) {

return;
}

if (this.overlayDecoration) {
const editor = atom.workspace.getActiveTextEditor();

if (!editor) {

return;
}

const marker = editor.getLastCursor && editor.getLastCursor().getMarker();
const marker = editor.getLastCursor().getMarker();

if (!marker) {

Expand All @@ -71,16 +70,7 @@ class Type {
});
}

queryType(editor, cursor) {

if (
!cursor ||
cursor.destroyed ||
!manager.client
) {

return;
}
queryType(editor, e) {

let rowStart = 0;
let rangeBefore = false;
Expand All @@ -90,7 +80,7 @@ class Type {
let skipCounter = 0;
let skipCounter2 = 0;
let paramPosition = 0;
const position = cursor.getBufferPosition();
const position = e.newBufferPosition;
const buffer = editor.getBuffer();

if (position.row - TOLERANCE < 0) {
Expand Down Expand Up @@ -194,7 +184,6 @@ class Type {

if (!rangeBefore) {

this.scopeLost = true;
this.currentViewData = null;
this.currentRange = null;
this.destroyOverlay();
Expand All @@ -204,19 +193,16 @@ class Type {

if (rangeBefore.isEqual(this.currentRange)) {

this.scopeLost = false;

this.currentViewData && this.setViewData(this.currentViewData, paramPosition);

return;
}

this.currentRange = rangeBefore;
this.scopeLost = true;
this.currentViewData = null;
this.destroyOverlay();

manager.client.update(editor).then((data) => {
manager.client.update(editor).then(() => {

manager.client.type(editor, rangeBefore.start).then((data) => {

Expand Down Expand Up @@ -251,8 +237,7 @@ class Type {

if (params && params[paramPosition]) {

const offsetFix = paramPosition > 0 ? ' ' : '';
viewData.type = viewData.type.replace(params[paramPosition], `${offsetFix}<span class="text-info">${params[paramPosition]}</span>`);
viewData.type = viewData.type.replace(params[paramPosition], `<span class="text-info">${params[paramPosition]}</span>`);
}

if (
Expand All @@ -262,9 +247,13 @@ class Type {

viewData.doc = viewData.doc && viewData.doc.replace(/(?:\r\n|\r|\n)/g, '<br />');
viewData.doc = prepareInlineDocs(viewData.doc);
}

this.view.setData(viewData);
this.view.setData(viewData.type, viewData.doc);

} else {

this.view.setData(viewData.type);
}

this.setPosition();
}
Expand All @@ -281,7 +270,7 @@ class Type {

destroy() {

emitter.off('destroy-type-overlay', this.destroyOverlayHandler);
emitter.off('destroy-type-overlay', this.destroyOverlayListener);

this.destroyOverlay();

Expand Down
4 changes: 2 additions & 2 deletions styles/atom-ternjs.less
Expand Up @@ -114,6 +114,7 @@ atom-ternjs-reference {

.atom-ternjs-type {

padding: 5px 20px;
border: 1px solid @base-border-color;
}

Expand All @@ -127,8 +128,7 @@ atom-ternjs-documentation {
}
}

atom-ternjs-documentation,
atom-ternjs-type {
atom-ternjs-documentation {

> div:not(:empty) {

Expand Down

0 comments on commit 36127e0

Please sign in to comment.