-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Anton Kosyakov <[email protected]>
- Loading branch information
Showing
9 changed files
with
178 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
packages/core/src/browser/quick-open/quick-pick-service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
packages/typescript/src/browser/typescript-frontend-contribution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -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" | ||
|
@@ -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" | ||
|
@@ -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" | ||
|
||
|
@@ -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" | ||
|