Skip to content

Commit

Permalink
feat(lsp): add multi config & multi-root workspace support
Browse files Browse the repository at this point in the history
Client (closes flow#302, flow#304, flow#253, flow#228, flow#201, flow#195, flow#189, flow#184, flow#165, flow#81)
- add multi flowconfig support
- add vscode multi-root workspace support
- client is now lazily created if flowconfig found
- fix document selector.

New implementation will handle following cases
- Single workspace with multiple flowconfig
- Multiple workspace with multiple flowconfig

Get Flow-Bin
- improve|fix logic to find flow-bin (fixes flow#282, flow#240, flow#209)
- fix flow bundled with plugin not working
  issue: we are using .bin/flow but vscode never includes .bin in plugin package
- add logs while finding flow-bin to debug issues
- plugin now doesn't check for node (closes flow#290)
- pathToFlow: value is normalized and .cmd is added so same value can
be used for linux, osx & win

Error handling (closes flow#200)
- [feat] improve error handling.
- [feat] Show action in errors so that user can recover from error
  without restarting vscode

Commands
- [feat] Add commands
  - Toggle coverage
  - Show client status
  - Restart Client
  - Log Client Debug Info
  - Show output channel

Status Widget
Include more info in status widget to help user know what this plugin is using
- [feat] include flow version
- [feat] add flow info section in widget tooltip which includes
  - path to .flowconfig
  - flow version
  - path to "flow" binary

Settings
- flow.coverageSeverity to control type coverage diagnostic severity
- flow.useBundledFlow control use of flow bundled with this plugin
- flow.trace.server log communication between vscode and flow lsp
- flow.logLevel control log level of plugin logs
  • Loading branch information
Mayank1791989 committed Feb 16, 2019
1 parent e5ea787 commit 00a4697
Show file tree
Hide file tree
Showing 47 changed files with 2,359 additions and 549 deletions.
158 changes: 134 additions & 24 deletions flow-libs/vscode-languageclient.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*/

declare module 'vscode-languageclient' {
declare type Thenable<R> = Promise<R>;

import type {
ClientCapabilities,
DocumentSelector,
Expand All @@ -32,10 +34,21 @@ declare module 'vscode-languageclient' {
IDisposable as _IDisposable,
TextDocument,
Position as VPosition,
Location as VLocation,
Definition as VDefinition,
CompletionContext as VCompletionContext,
CompletionList as VCompletionList,
CompletionItem as VCompletionItem,
SignatureHelp as VSignatureHelp,
DocumentHighlight as VDocumentHighlight,
SymbolInformation as VSymbolInformation,
WorkspaceEdit as VWorkspaceEdit,
Range as VRange,
ProviderResult,
Hover as VHover,
WorkspaceFolder as VWorkspaceFolder,
Uri,
TextDocumentChangeEvent,
} from 'vscode';

declare export * from 'vscode-languageserver-protocol'
Expand Down Expand Up @@ -234,46 +247,141 @@ declare module 'vscode-languageclient' {
): ProviderResult<VHover>;
}

// declare export interface Middleware {
// provideHover?: (uri: any, diagnostics: any[], next: HandleDiagnosticsSignature) => void;
// handleDiagnostics?: (uri: any, diagnostics: any[], next: HandleDiagnosticsSignature) => void;
// }

declare export interface Middleware {
// didOpen?: NextSignature<TextDocument, void>;
// didChange?: NextSignature<TextDocumentChangeEvent, void>;
declare type NextSignature<P, R> = (data: P, next: (data: P) => R) => R;
declare export type ProvideReferencesSignature = (
document: TextDocument,
position: VPosition,
options: { includeDeclaration: boolean; },
token: CancellationToken
) => ProviderResult<VLocation[]>;
declare export type ProvideDefinitionSignature = (
document: TextDocument,
position: VPosition,
token: CancellationToken
) => ProviderResult<VDefinition>;
declare export type ProvideCompletionItemsSignature = (
document: TextDocument,
position: VPosition,
context: VCompletionContext,
token: CancellationToken
) => ProviderResult<VCompletionItem[] | VCompletionList>;
declare export type ProvideSignatureHelpSignature = (
document: TextDocument,
position: VPosition,
token: CancellationToken
) => ProviderResult<VSignatureHelp>;
declare export type ProvideDocumentHighlightsSignature = (
document: TextDocument,
position: VPosition,
token: CancellationToken
) => ProviderResult<VDocumentHighlight[]>;
declare export type ProvideDocumentSymbolsSignature = (
document: TextDocument,
token: CancellationToken
) => ProviderResult<VSymbolInformation[]>;
declare export type ProvideWorkspaceSymbolsSignature = (
query: string,
token: CancellationToken
) => ProviderResult<VSymbolInformation[]>;
declare export type ProvideRenameEditsSignature = (
document: TextDocument,
position: VPosition,
newName: string,
token: CancellationToken
) => ProviderResult<VWorkspaceEdit>;
declare export type PrepareRenameSignature = (
document: TextDocument,
position: VPosition,
token: CancellationToken
) => ProviderResult<VRange | { range: VRange; placeholder: string; }>;

declare export type Middleware = {
didOpen?: NextSignature<TextDocument, void>,
didChange?: NextSignature<TextDocumentChangeEvent, void>;
// willSave?: NextSignature<TextDocumentWillSaveEvent, void>;
// willSaveWaitUntil?: NextSignature<TextDocumentWillSaveEvent, Thenable<VTextEdit[]>>;
// didSave?: NextSignature<TextDocument, void>;
// didClose?: NextSignature<TextDocument, void>;
didSave?: NextSignature<TextDocument, void>,
didClose?: NextSignature<TextDocument, void>,

// handleDiagnostics?: (uri: Uri, diagnostics: VDiagnostic[], next: HandleDiagnosticsSignature) => void;
// provideCompletionItem?: (document: TextDocument, position: VPosition, context: VCompletionContext, token: CancellationToken, next: ProvideCompletionItemsSignature) => ProviderResult<VCompletionItem[] | VCompletionList>;
provideCompletionItem?: (
document: TextDocument,
position: VPosition,
context: VCompletionContext,
token: CancellationToken,
next: ProvideCompletionItemsSignature
) => ProviderResult<VCompletionItem[] | VCompletionList>;
// resolveCompletionItem?: (item: VCompletionItem, token: CancellationToken, next: ResolveCompletionItemSignature) => ProviderResult<VCompletionItem>;
provideHover?: (
document: TextDocument,
position: VPosition,
token: CancellationToken,
next: ProvideHoverSignature,
) => ProviderResult<VHover>;
// provideSignatureHelp?: (document: TextDocument, position: VPosition, token: CancellationToken, next: ProvideSignatureHelpSignature) => ProviderResult<VSignatureHelp>;
// provideDefinition?: (document: TextDocument, position: VPosition, token: CancellationToken, next: ProvideDefinitionSignature) => ProviderResult<VDefinition>;
// provideReferences?: (document: TextDocument, position: VPosition, options: { includeDeclaration: boolean; }, token: CancellationToken, next: ProvideReferencesSignature) => ProviderResult<VLocation[]>;
// provideDocumentHighlights?: (document: TextDocument, position: VPosition, token: CancellationToken, next: ProvideDocumentHighlightsSignature) => ProviderResult<VDocumentHighlight[]>;
// provideDocumentSymbols?: (document: TextDocument, token: CancellationToken, next: ProvideDocumentSymbolsSignature) => ProviderResult<VSymbolInformation[] | VDocumentSymbol[]>;
// provideWorkspaceSymbols?: (query: string, token: CancellationToken, next: ProvideWorkspaceSymbolsSignature) => ProviderResult<VSymbolInformation[]>;
) => ProviderResult<VHover>,

provideSignatureHelp?: (
document: TextDocument,
position: VPosition,
token: CancellationToken,
next: ProvideSignatureHelpSignature
) => ProviderResult<VSignatureHelp>;

provideDefinition?: (
document: TextDocument,
position: VPosition,
token: CancellationToken,
next: ProvideDefinitionSignature
) => ProviderResult<VDefinition>;

provideReferences?: (
document: TextDocument,
position: VPosition,
options: { includeDeclaration: boolean; },
token: CancellationToken,
next: ProvideReferencesSignature
) => ProviderResult<VLocation[]>;

provideDocumentHighlights?: (
document: TextDocument,
position: VPosition,
token: CancellationToken,
next: ProvideDocumentHighlightsSignature
) => ProviderResult<VDocumentHighlight[]>;

provideDocumentSymbols?: (
document: TextDocument,
token: CancellationToken,
next: ProvideDocumentSymbolsSignature
) => ProviderResult<VSymbolInformation[]>;

provideWorkspaceSymbols?: (
query: string,
token: CancellationToken,
next: ProvideWorkspaceSymbolsSignature
) => ProviderResult<VSymbolInformation[]>;
// provideCodeActions?: (document: TextDocument, range: VRange, context: VCodeActionContext, token: CancellationToken, next: ProvideCodeActionsSignature) => ProviderResult<(VCommand | VCodeAction)[]>;
// provideCodeLenses?: (document: TextDocument, token: CancellationToken, next: ProvideCodeLensesSignature) => ProviderResult<VCodeLens[]>;
// resolveCodeLens?: (codeLens: VCodeLens, token: CancellationToken, next: ResolveCodeLensSignature) => ProviderResult<VCodeLens>;
// provideDocumentFormattingEdits?: (document: TextDocument, options: VFormattingOptions, token: CancellationToken, next: ProvideDocumentFormattingEditsSignature) => ProviderResult<VTextEdit[]>;
// provideDocumentRangeFormattingEdits?: (document: TextDocument, range: VRange, options: VFormattingOptions, token: CancellationToken, next: ProvideDocumentRangeFormattingEditsSignature) => ProviderResult<VTextEdit[]>;
// provideOnTypeFormattingEdits?: (document: TextDocument, position: VPosition, ch: string, options: VFormattingOptions, token: CancellationToken, next: ProvideOnTypeFormattingEditsSignature) => ProviderResult<VTextEdit[]>;
// provideRenameEdits?: (document: TextDocument, position: VPosition, newName: string, token: CancellationToken, next: ProvideRenameEditsSignature) => ProviderResult<VWorkspaceEdit>;
// prepareRename?: (document: TextDocument, position: VPosition, token: CancellationToken, next: PrepareRenameSignature) => ProviderResult<VRange | { range: VRange, placeholder: string }>;
provideRenameEdits?: (
document: TextDocument,
position: VPosition,
newName: string,
token: CancellationToken,
next: ProvideRenameEditsSignature
) => ProviderResult<VWorkspaceEdit>;
prepareRename?: (
document: TextDocument,
position: VPosition,
token: CancellationToken,
next: PrepareRenameSignature
) => ProviderResult<VRange | { range: VRange, placeholder: string }>;
// provideDocumentLinks?: (document: TextDocument, token: CancellationToken, next: ProvideDocumentLinksSignature) => ProviderResult<VDocumentLink[]>;
// resolveDocumentLink?: (link: VDocumentLink, token: CancellationToken, next: ResolveDocumentLinkSignature) => ProviderResult<VDocumentLink>;
// workspace?: WorkspaceMiddleware;
}
};

/**
* A pluggable error handler that is invoked when the connection is either
Expand Down Expand Up @@ -311,7 +419,7 @@ declare module 'vscode-languageclient' {
initializationOptions?: any,
initializationFailedHandler?: (error: any) => boolean,
errorHandler?: ErrorHandler,
middleware?: Middleware,
+middleware?: Middleware,
uriConverters?: {
code2Protocol: c2p$URIConverter,
protocol2Code: p2c$URIConverter,
Expand Down Expand Up @@ -360,7 +468,7 @@ declare module 'vscode-languageclient' {
}

declare export class TextDocumentFeature<T> implements DynamicFeature<T> {
_client: LanguageClient;
+_client: LanguageClient;
_providers: Map<string, IDisposable>;
messages: RPCMessageType;
constructor(_client: LanguageClient, _message: RPCMessageType): this;
Expand All @@ -376,7 +484,8 @@ declare module 'vscode-languageclient' {
}

declare export class LanguageClient {
get clientOptions(): LanguageClientOptions;
_clientOptions: LanguageClientOptions;
+clientOptions: LanguageClientOptions;
get outputChannel(): OutputChannel;
constructor(
name: string,
Expand Down Expand Up @@ -412,6 +521,7 @@ declare module 'vscode-languageclient' {
stop(): Thenable<void>;
onReady(): Thenable<void>;
registerFeature(feature: StaticFeature | DynamicFeature<any>): void;
registerBuiltinFeatures(): void;
+onDidChangeState: Event<StateChangeEvent>;

onNotification<P, RO>(type: NotificationType<P, RO>, handler: NotificationHandler<P>): void;
Expand Down
21 changes: 12 additions & 9 deletions flow-libs/vscode-languageserver-protocol.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ declare module 'vscode-languageserver-protocol' {
RequestType as _RequestType,
NotificationType as _NotificationType,
} from 'vscode-jsonrpc';

import type {
RequestHandler as _RequestHandler,
NotificationHandler as _NotificationHandler,
Message as _Message,
} from 'vscode-jsonrpc';

import type { GlobPattern } from 'vscode';

declare export var RequestType: _RequestType;
declare export var NotificationType: _NotificationType;
declare export type RequestHandler<P, R, E> = _RequestHandler<P, R, E>;
Expand Down Expand Up @@ -56,30 +59,30 @@ declare module 'vscode-languageserver-protocol' {
};

declare export type DocumentFilter =
| {
| {|
/** A language id, like `typescript`. */
language: string,
/** A Uri [scheme](#Uri.scheme), like `file` or `untitled`. */
scheme?: string,
/** A glob pattern, like `*.{ts,js}`. */
pattern?: string
}
| {
pattern?: GlobPattern,
|}
| {|
/** A language id, like `typescript`. */
language?: string,
/** A Uri [scheme](#Uri.scheme), like `file` or `untitled`. */
scheme: string,
/** A glob pattern, like `*.{ts,js}`. */
pattern?: string
}
| {
pattern?: GlobPattern
|}
| {|
/** A language id, like `typescript`. */
language?: string,
/** A Uri [scheme](#Uri.scheme), like `file` or `untitled`. */
scheme?: string,
/** A glob pattern, like `*.{ts,js}`. */
pattern: string
};
pattern: GlobPattern,
|};

declare export type DocumentSelector = Array<DocumentFilter | string>;

Expand Down
27 changes: 13 additions & 14 deletions flow-libs/vscode.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
// flow-typed version: b43dff3e0e/vscode_v1.1.10/flow_>=v0.28.x

declare module 'vscode' {
/**
* Thenable is a common denominator between ES6 promises, Q, jquery.Deferred, WinJS.Promise,
* and others. This API makes no assumption about what promise libary is being used which
* enables reusing existing code without migrating to a specific promise implementation. Still,
* we recommend the use of native promises which are available in this editor.
*/
declare type Thenable<R> = Promise<R>;

/**
* The version of the editor.
Expand Down Expand Up @@ -1334,7 +1341,7 @@ declare module 'vscode' {
/**
* Dispose this object.
*/
dispose(): any;
dispose(): void;
}

/**
Expand Down Expand Up @@ -1475,7 +1482,7 @@ declare module 'vscode' {
/**
* A human readable string which is rendered less prominent.
*/
description: string;
description?: string;

/**
* A human readable string which is rendered less prominent.
Expand Down Expand Up @@ -5188,18 +5195,18 @@ declare module 'vscode' {
/**
* An event describing a transactional [document](#TextDocument) change.
*/
declare export interface TextDocumentChangeEvent {
declare export type TextDocumentChangeEvent = {

/**
* The affected document.
*/
document: TextDocument;
document: TextDocument,

/**
* An array of content changes.
*/
contentChanges: TextDocumentContentChangeEvent[];
}
contentChanges: TextDocumentContentChangeEvent[],
};

/**
* Represents reasons why a text document is saved.
Expand Down Expand Up @@ -7250,11 +7257,3 @@ declare module 'vscode' {
/* END PROPOSED *********************************************************************************/

}

/**
* Thenable is a common denominator between ES6 promises, Q, jquery.Deferred, WinJS.Promise,
* and others. This API makes no assumption about what promise libary is being used which
* enables reusing existing code without migrating to a specific promise implementation. Still,
* we recommend the use of native promises which are available in this editor.
*/
declare type Thenable<R> = Promise<R>;
33 changes: 33 additions & 0 deletions flow-typed/npm/bin-version_vx.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// flow-typed signature: a2bf291ab27d143ffdae5002d33d8329
// flow-typed version: <<STUB>>/bin-version_v3.0.0/flow_v0.92.0

/**
* This is an autogenerated libdef stub for:
*
* 'bin-version'
*
* Fill this stub out by replacing all the `any` types.
*
* Once filled out, we encourage you to share your work with the
* community by sending a pull request to:
* https://github.com/flowtype/flow-typed
*/

declare module 'bin-version' {
declare module.exports: any;
}

/**
* We include stubs for each file inside this npm package in case you need to
* require those files directly. Feel free to delete any files that aren't
* needed.
*/


// Filename aliases
declare module 'bin-version/index' {
declare module.exports: $Exports<'bin-version'>;
}
declare module 'bin-version/index.js' {
declare module.exports: $Exports<'bin-version'>;
}
Loading

0 comments on commit 00a4697

Please sign in to comment.