Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing features in useLSP mode #295

Merged
merged 15 commits into from
Dec 19, 2018
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .babelrc

This file was deleted.

26 changes: 26 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

// NOTE: using babel.config.js instead of .babelrc to force
// babel to compile files inside lib/pkg/* using this config

module.exports = function(api) {
api.env();

return {
plugins: ['@babel/plugin-proposal-class-properties'],

presets: [
[
'@babel/preset-env',
{
targets: {
node: '6'
}
}
],
'@babel/preset-flow'
],

ignore: ['node_modules']
};
};
4 changes: 2 additions & 2 deletions lib/flowHover.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

import * as vscode from 'vscode'
import { js_beautify } from 'js-beautify'
import { format } from './utils';

import {flowGetType} from './pkg/flow-base/lib/FlowService'

Expand All @@ -35,7 +35,7 @@ export class HoverSupport {
)

if (completions) {
const beautifiedData = js_beautify(completions.type, { indent_size: 4 });
const beautifiedData = format(completions.type);
return new vscode.Hover([
'[Flow]',
{language: 'javascript', value: `${word}: ${beautifiedData}`}
Expand Down
119 changes: 0 additions & 119 deletions lib/flowLSP.js

This file was deleted.

140 changes: 140 additions & 0 deletions lib/flowLSP/features/Status/Status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/* @flow */
import * as vscode from 'vscode';
import { LspMessageType, type StatusData } from './types';
import StatusProvider from './StatusProvider';
import StatusBarWidget from '../StatusBarWidget';

type State = {
status: StatusData,
};

export default class Status {
state: State = {
status: { kind: 'null' },
};

_provider: StatusProvider;
_widget: StatusBarWidget;
_command: vscode.Disposable;

constructor(provider: StatusProvider, widget: StatusBarWidget) {
this._widget = widget;
this._provider = provider;
this._provider.onStatus(statusData => {
this.setState({ status: statusData });
});
// register command to handle show current server status
this._command = vscode.commands.registerCommand(
'flow.show-status',
this._handleShowStatus,
);
}

setState(partialState: $Shape<State>) {
this.state = {
...this.state,
...partialState,
};
this.render();
}

render() {
const item = this._widget;
const { status } = this.state;

switch (status.kind) {
case 'green':
this._widget.setStatus({
state: 'idle',
message: status.message || '',
});
break;
case 'yellow':
this._widget.setStatus({
state: 'busy',
progress: this._getProgress(status),
message: status.message || '',
});
break;
case 'red':
this._widget.setStatus({
state: 'error',
message: status.message || '',
});
break;
case 'null':
this._widget.setStatus(null);
default:
this._widget.setStatus(null);
break;
}
}

_getProgress(status: StatusData): string {
if (status.kind !== 'yellow') {
return '';
}
if (status.shortMessage != null) {
return status.shortMessage;
}
if (status.progress != null) {
const { numerator, denominator } = status.progress;
return (
Math.round(
(numerator / (denominator == null ? 100 : denominator)) * 100,
) + '%'
);
}

if (status.message != null) {
// remove `Flow:` from message
return status.message.replace('Flow:', '');
}

return '';
}

_handleShowStatus = () => {
const { status } = this.state;
switch (status.kind) {
case 'red': {
const items = status.buttons.map(button => ({
title: button,
command: () => this._provider.clickAction(status.id || '', button),
}));
vscode.window
.showErrorMessage(status.message || '', ...items)
.then(selection => {
if (selection) {
selection.command();
}
});
break;
}
case 'yellow': {
const items = status.buttons.map(button => ({
title: button,
command: () => this._provider.clickAction(status.id || '', button),
}));
vscode.window
.showWarningMessage(status.message || '', ...items)
.then(selection => {
if (selection) {
selection.command();
}
});
break;
}
case 'green': {
vscode.window.showInformationMessage(status.message || '');
break;
}
default:
break;
}
};

dispose() {
this._command.dispose();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we dispose StatusProvider as well, just not to forget about it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thymikee Actually there is nothing in StatusProvider to dispose so I kept it this way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember a comment about adding such in StatusProvider. Maybe worth removing it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I should remove the onStatus listener in dispose method. As provider and status component both disposes together it will not cause any issues but I will push a fix thanks.

}
}
30 changes: 30 additions & 0 deletions lib/flowLSP/features/Status/StatusFeature.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* @flow */
// add support using "window/showStatus" lsp extension
import * as lsp from 'vscode-languageclient';
import * as vscode from 'vscode';
import StatusProvider from './StatusProvider';
import Status from './Status';
import { type ShowStatusParams, LspMessageType } from './types';
import StatusBarWidget from '../StatusBarWidget';

type StaticFeature = lsp.StaticFeature;

export default class StatusFeature implements StaticFeature {
_client: lsp.BaseLanguageClient;
_widget: StatusBarWidget;

constructor(client: lsp.BaseLanguageClient, widget: StatusBarWidget) {
this._client = client;
this._widget = widget;
}

fillClientCapabilities(capabilities: lsp.ClientCapabilities): void {
capabilities.window = capabilities.window || {};
capabilities.window.status = { dynamicRegistration: false };
}

initialize(): lsp.Disposable {
const statusProvider = new StatusProvider(this._client);
return new Status(statusProvider, this._widget);
}
}
Loading