Skip to content

Commit

Permalink
upgrade TS language server
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Kosyakov <[email protected]>
  • Loading branch information
akosyakov committed Aug 7, 2018
1 parent a821f30 commit f753ecb
Show file tree
Hide file tree
Showing 9 changed files with 178 additions and 44 deletions.
3 changes: 2 additions & 1 deletion packages/core/src/browser/frontend-application-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { FrontendApplication, FrontendApplicationContribution, DefaultFrontendAp
import { DefaultOpenerService, OpenerService, OpenHandler } from './opener-service';
import { HttpOpenHandler } from './http-open-handler';
import { CommonFrontendContribution } from './common-frontend-contribution';
import { QuickOpenService, QuickCommandService, QuickCommandFrontendContribution } from './quick-open';
import { QuickOpenService, QuickCommandService, QuickCommandFrontendContribution, QuickPickService } from './quick-open';
import { LocalStorageService, StorageService } from './storage-service';
import { WidgetFactory, WidgetManager } from './widget-manager';
import {
Expand Down Expand Up @@ -118,6 +118,7 @@ export const frontendApplicationModule = new ContainerModule((bind, unbind, isBo
);

bind(QuickOpenService).toSelf().inSingletonScope();
bind(QuickPickService).toSelf().inSingletonScope();
bind(QuickCommandService).toSelf().inSingletonScope();
bind(QuickCommandFrontendContribution).toSelf().inSingletonScope();
[CommandContribution, KeybindingContribution].forEach(serviceIdentifier =>
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/browser/quick-open/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@

export * from './quick-open-model';
export * from './quick-open-service';
export * from './quick-pick-service';
export * from './quick-command-service';
export * from './quick-command-contribution';
68 changes: 68 additions & 0 deletions packages/core/src/browser/quick-open/quick-pick-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/********************************************************************************
* Copyright (C) 2018 TypeFox and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { injectable, inject } from 'inversify';
import { QuickOpenItem, QuickOpenMode } from './quick-open-model';
import { QuickOpenService } from './quick-open-service';

export interface QuickPickItem<T> {
label: string,
value: T
}

export interface QuickPickOptions {
placeholder?: string;
}

@injectable()
export class QuickPickService {

@inject(QuickOpenService)
protected readonly quickOpenService: QuickOpenService;

show(elements: string[], options?: QuickPickOptions): Promise<string | undefined>;
show<T>(elements: QuickPickItem<T>[], options?: QuickPickOptions): Promise<T | undefined>;
async show(elements: (string | QuickPickItem<Object>)[], options?: QuickPickOptions): Promise<Object | undefined> {
if (elements.length === 0) {
return undefined;
}
if (elements.length === 1) {
return elements[0];
}
return new Promise<Object | undefined>(resolve => {
const items = elements.map(element => {
const label = typeof element === 'string' ? element : element.label;
const value = typeof element === 'string' ? element : element.value;
return new QuickOpenItem({
label,
run: mode => {
if (mode !== QuickOpenMode.OPEN) {
return false;
}
resolve(value);
return true;
}
});
});
this.quickOpenService.open({
onType: (lookFor, acceptor) => acceptor(items)
}, Object.assign({
onClose: () => resolve(undefined)
}, options));
});
}

}
44 changes: 9 additions & 35 deletions packages/git/src/browser/git-sync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { injectable, inject } from 'inversify';
import { MessageService, Emitter, Event } from '@theia/core';
import { QuickOpenService, QuickOpenItem, QuickOpenMode, ConfirmDialog } from '@theia/core/lib/browser';
import { QuickPickService, ConfirmDialog } from '@theia/core/lib/browser';
import { GitRepositoryTracker } from './git-repository-tracker';
import { Git, Repository, WorkingDirectoryStatus } from '../common';
import { GitErrorHandler } from './git-error-handler';
Expand All @@ -36,8 +36,8 @@ export class GitSyncService {
@inject(GitErrorHandler)
protected readonly gitErrorHandler: GitErrorHandler;

@inject(QuickOpenService)
protected readonly quickOpenService: QuickOpenService;
@inject(QuickPickService)
protected readonly quickPickService: QuickPickService;

protected readonly onDidChangeEmitter = new Emitter<void>();
readonly onDidChange: Event<void> = this.onDidChangeEmitter.event;
Expand Down Expand Up @@ -121,7 +121,9 @@ export class GitSyncService {
warning: `This action will override commits in '${upstreamBranch}'.`,
value: 'force-push'
}];
const method = await this.pick('Pick how changes should be synchronized:', methods);
const method = await this.quickPickService.show(methods, {
placeholder: 'Pick how changes should be synchronized:'
});
if (method && await this.confirm('Synchronize Changes', methods.find(({ value }) => value === method)!.warning)) {
return method;
}
Expand Down Expand Up @@ -160,7 +162,9 @@ export class GitSyncService {
if (remotes.length === 0) {
this.messageService.warn('Your repository has no remotes configured to publish to.');
}
return this.pick(`Pick a remote to publish the branch ${branch} to:`, remotes);
return this.quickPickService.show(remotes, {
placeholder: `Pick a remote to publish the branch ${branch} to:`
});
}

protected shouldPush(status: WorkingDirectoryStatus): boolean {
Expand All @@ -170,36 +174,6 @@ export class GitSyncService {
return status.aheadBehind ? status.aheadBehind.behind > 0 : true;
}

protected pick(placeholder: string, elements: string[]): Promise<string | undefined>;
protected pick<T>(placeholder: string, elements: { label: string, value: T }[]): Promise<T | undefined>;
protected async pick(placeholder: string, elements: (string | { label: string, value: Object })[]): Promise<Object | undefined> {
if (elements.length === 0) {
return undefined;
}
if (elements.length === 1) {
return elements[0];
}
return new Promise<Object | undefined>(resolve => {
const items = elements.map(element => {
const label = typeof element === 'string' ? element : element.label;
const value = typeof element === 'string' ? element : element.value;
return new QuickOpenItem({
label,
run: mode => {
if (mode !== QuickOpenMode.OPEN) {
return false;
}
resolve(value);
return true;
}
});
});
this.quickOpenService.open({
onType: (lookFor, acceptor) => acceptor(items)
}, { placeholder, onClose: () => resolve(undefined) });
});
}

protected async confirm(title: string, msg: string): Promise<boolean> {
return !!await new ConfirmDialog({ title, msg, }).open();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/languages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@theia/output": "^0.3.13",
"@theia/process": "^0.3.13",
"@theia/workspace": "^0.3.13",
"monaco-languageclient": "^0.7.2"
"monaco-languageclient": "next"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@theia/core": "^0.3.13",
"@theia/languages": "^0.3.13",
"@theia/monaco": "^0.3.13",
"typescript-language-server": "^0.2.0"
"typescript-language-server": "next"
},
"publishConfig": {
"access": "public"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/********************************************************************************
* Copyright (C) 2018 TypeFox and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { injectable, inject } from 'inversify';
import * as tsp from 'typescript/lib/protocol';
import { Commands } from 'typescript-language-server/lib/commands';
import { QuickPickService } from '@theia/core/lib/browser';
import { ExecuteCommandRequest } from '@theia/languages/lib/browser';
import { CommandContribution, CommandRegistry, Command } from '@theia/core/lib/common';
import { TypeScriptClientContribution } from './typescript-client-contribution';

export namespace TypeScriptCommands {
export const applyCompletionCodeAction: Command = {
id: Commands.APPLY_COMPLETION_CODE_ACTION
};
}

@injectable()
export class TypeScriptFrontendContribution implements CommandContribution {

@inject(QuickPickService)
protected readonly quickPickService: QuickPickService;

@inject(TypeScriptClientContribution)
protected readonly clientContribution: TypeScriptClientContribution;

registerCommands(commands: CommandRegistry): void {
commands.registerCommand(TypeScriptCommands.applyCompletionCodeAction, {
execute: async (file: string, codeActions: tsp.CodeAction[]) => {
const codeAction = await this.pickCodeAction(codeActions);
return codeAction && this.applyCodeAction(codeAction);
}
});
}

protected pickCodeAction(codeActions: tsp.CodeAction[]): Promise<tsp.CodeAction | undefined> {
return this.quickPickService.show<tsp.CodeAction>(codeActions.map(value => ({
label: value.description,
value
}), {
placeholder: 'Select code action to apply'
}
));
}

protected async applyCodeAction(codeAction: tsp.CodeAction): Promise<any> {
const client = await this.clientContribution.languageClient;
return client.sendRequest(ExecuteCommandRequest.type, {
command: Commands.APPLY_CODE_ACTION,
arguments: [codeAction]
});
}

}
5 changes: 5 additions & 0 deletions packages/typescript/src/browser/typescript-frontend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
********************************************************************************/

import { ContainerModule } from 'inversify';
import { CommandContribution } from '@theia/core/lib/common';
import { LanguageGrammarDefinitionContribution } from '@theia/monaco/lib/browser/textmate';
import { LanguageClientContribution } from '@theia/languages/lib/browser';
import { CallHierarchyService } from '@theia/callhierarchy/lib/browser';
import { TypeScriptClientContribution } from './typescript-client-contribution';
import { TypeScriptCallHierarchyService } from './typescript-callhierarchy-service';
import { TypescriptGrammarContribution } from './typescript-language-config';
import { JavascriptGrammarContribution } from './javascript-language-config';
import { TypeScriptFrontendContribution } from './typescript-frontend-contribution';

export default new ContainerModule(bind => {
bind(TypeScriptClientContribution).toSelf().inSingletonScope();
Expand All @@ -32,4 +34,7 @@ export default new ContainerModule(bind => {

bind(LanguageGrammarDefinitionContribution).to(TypescriptGrammarContribution).inSingletonScope();
bind(LanguageGrammarDefinitionContribution).to(JavascriptGrammarContribution).inSingletonScope();

bind(TypeScriptFrontendContribution).toSelf().inSingletonScope();
bind(CommandContribution).toService(TypeScriptFrontendContribution);
});
30 changes: 24 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2757,6 +2757,10 @@ crypto-browserify@^3.11.0:
randombytes "^2.0.0"
randomfill "^1.0.3"

crypto-random-string@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/crypto-random-string/-/crypto-random-string-1.0.0.tgz#a230f64f568310e1498009940790ec99545bca7e"

[email protected]:
version "0.0.4"
resolved "https://registry.yarnpkg.com/css-color-names/-/css-color-names-0.0.4.tgz#808adc2e79cf84738069b646cb20ec27beb629e0"
Expand Down Expand Up @@ -6376,9 +6380,9 @@ monaco-html@^2.0.2:
version "2.1.1"
resolved "https://registry.yarnpkg.com/monaco-html/-/monaco-html-2.1.1.tgz#464572924e3e0ab05a0e8e6abbbda166f400b25c"

monaco-languageclient@^0.7.2:
version "0.7.2"
resolved "https://registry.yarnpkg.com/monaco-languageclient/-/monaco-languageclient-0.7.2.tgz#74a9db05ad4303a8b64ee3f16b8d2e41478b28ae"
monaco-languageclient@next:
version "0.8.0-next.3"
resolved "https://registry.yarnpkg.com/monaco-languageclient/-/monaco-languageclient-0.8.0-next.3.tgz#4dda6d8a193a2a62471d36d04f370d6f3fd996dc"
dependencies:
glob-to-regexp "^0.3.0"
monaco-editor-core "^0.13.2"
Expand Down Expand Up @@ -9122,6 +9126,13 @@ tempfile@^1.1.1:
os-tmpdir "^1.0.0"
uuid "^2.0.1"

tempy@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/tempy/-/tempy-0.2.1.tgz#9038e4dbd1c201b74472214179bc2c6f7776e54c"
dependencies:
temp-dir "^1.0.0"
unique-string "^1.0.0"

test-exclude@^4.2.0:
version "4.2.1"
resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-4.2.1.tgz#dfa222f03480bca69207ca728b37d74b45f724fa"
Expand Down Expand Up @@ -9428,12 +9439,13 @@ typedoc@^0.8:
typedoc-default-themes "^0.5.0"
typescript "2.4.1"

typescript-language-server@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/typescript-language-server/-/typescript-language-server-0.2.0.tgz#c472b26ea9eb078158b742b4b7315209864a1c82"
typescript-language-server@next:
version "0.3.0-next.1e8dc72"
resolved "https://registry.yarnpkg.com/typescript-language-server/-/typescript-language-server-0.3.0-next.1e8dc72.tgz#c7aca47ad0e8f8b0aff4eb13ab3f29e8c04da14a"
dependencies:
command-exists "1.2.6"
commander "^2.11.0"
tempy "^0.2.1"
vscode-languageserver "^4.4.0"
vscode-uri "^1.0.5"

Expand Down Expand Up @@ -9542,6 +9554,12 @@ unique-slug@^2.0.0:
dependencies:
imurmurhash "^0.1.4"

unique-string@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/unique-string/-/unique-string-1.0.0.tgz#9e1057cca851abb93398f8b33ae187b99caec11a"
dependencies:
crypto-random-string "^1.0.0"

universalify@^0.1.0:
version "0.1.2"
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66"
Expand Down

0 comments on commit f753ecb

Please sign in to comment.