use next release of coc.nvim

This commit is contained in:
Qiming Zhao 2020-12-17 20:28:49 +08:00
parent a98c4808f8
commit 954e292f2f
39 changed files with 181 additions and 3337 deletions

View file

@ -17,9 +17,8 @@
"typescript" "typescript"
], ],
"scripts": { "scripts": {
"clean": "rimraf lib", "build": "npx webpack",
"build": "webpack", "prepare": "npx webpack"
"prepare": "webpack"
}, },
"activationEvents": [ "activationEvents": [
"onLanguage:javascript", "onLanguage:javascript",
@ -623,17 +622,13 @@
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@types/node": "^10.12.0", "@types/node": "^10.12.0",
"coc.nvim": "^0.0.79", "coc.nvim": "^0.0.79-next.18",
"rimraf": "^3.0.2",
"semver": "^7.3.2", "semver": "^7.3.2",
"ts-loader": "^8.0.1", "ts-loader": "^8.0.1",
"vscode-languageserver-protocol": "^3.15.3", "vscode-languageserver-protocol": "^3.15.3",
"vscode-languageserver-textdocument": "^1.0.1",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.12",
"which": "^2.0.2" "which": "^2.0.2"
}, },
"dependencies": { "dependencies": {
"typescript": "4.1.2" "typescript": "^4.1.3"
} }
} }

View file

@ -24,10 +24,7 @@ export async function activate(context: ExtensionContext): Promise<API> {
registCommand(new OpenTsServerLogCommand(service)) registCommand(new OpenTsServerLogCommand(service))
registCommand(new TypeScriptGoToProjectConfigCommand(service)) registCommand(new TypeScriptGoToProjectConfigCommand(service))
registCommand(new OrganizeImportsCommand(service)) registCommand(new OrganizeImportsCommand(service))
registCommand({
service.start().then(() => {
subscriptions.push(services.regist(service))
registCommand(commands.register({
id: 'tsserver.restart', id: 'tsserver.restart',
execute: (): void => { execute: (): void => {
// tslint:disable-next-line:no-floating-promises // tslint:disable-next-line:no-floating-promises
@ -37,7 +34,10 @@ export async function activate(context: ExtensionContext): Promise<API> {
}, 100) }, 100)
}) })
} }
})) })
service.start().then(() => {
subscriptions.push(services.regist(service))
}, e => { }, e => {
logger.error(`Error on service start:`, e) logger.error(`Error on service start:`, e)
}) })

View file

@ -1,13 +1,12 @@
import { Uri as URI, diagnosticManager, workspace, commands, ServiceStat } from 'coc.nvim' import { commands, diagnosticManager, CancellationToken, Diagnostic, Disposable, ServiceStat, Uri as URI, window, workspace } from 'coc.nvim'
import { CancellationToken, Diagnostic } from 'vscode-languageserver-protocol' import { Range, TextEdit } from 'vscode-languageserver-types'
import TsserverService from '../server'
import { PluginManager } from '../utils/plugins'
import * as Proto from './protocol' import * as Proto from './protocol'
import TypeScriptServiceClientHost from './typescriptServiceClientHost' import TypeScriptServiceClientHost from './typescriptServiceClientHost'
import * as typeConverters from './utils/typeConverters'
import { TextEdit, Range } from 'vscode-languageserver-types'
import { installModules } from './utils/modules'
import { nodeModules } from './utils/helper' import { nodeModules } from './utils/helper'
import { PluginManager } from '../utils/plugins' import { installModules } from './utils/modules'
import TsserverService from '../server' import * as typeConverters from './utils/typeConverters'
export interface Command { export interface Command {
readonly id: string | string[] readonly id: string | string[]
@ -19,12 +18,12 @@ export class ReloadProjectsCommand implements Command {
public constructor( public constructor(
private readonly service: TsserverService private readonly service: TsserverService
) { } ) {}
public async execute(): Promise<void> { public async execute(): Promise<void> {
let client = await this.service.getClientHost() let client = await this.service.getClientHost()
client.reloadProjects() client.reloadProjects()
workspace.showMessage('projects reloaded') window.showMessage('projects reloaded')
} }
} }
@ -33,7 +32,7 @@ export class OpenTsServerLogCommand implements Command {
public constructor( public constructor(
private readonly service: TsserverService private readonly service: TsserverService
) { } ) {}
public async execute(): Promise<void> { public async execute(): Promise<void> {
let client = await this.service.getClientHost() let client = await this.service.getClientHost()
@ -46,7 +45,7 @@ export class TypeScriptGoToProjectConfigCommand implements Command {
public constructor( public constructor(
private readonly service: TsserverService private readonly service: TsserverService
) { } ) {}
public async execute(): Promise<void> { public async execute(): Promise<void> {
let client = await this.service.getClientHost() let client = await this.service.getClientHost()
@ -70,7 +69,7 @@ async function goToProjectConfig(clientHost: TypeScriptServiceClientHost, uri: s
// noop // noop
} }
if (!res || !res.body) { if (!res || !res.body) {
workspace.showMessage('Could not determine TypeScript or JavaScript project.', 'warning') window.showMessage('Could not determine TypeScript or JavaScript project.', 'warning')
return return
} }
const { configFileName } = res.body const { configFileName } = res.body
@ -78,7 +77,7 @@ async function goToProjectConfig(clientHost: TypeScriptServiceClientHost, uri: s
await workspace.openResource(URI.file(configFileName).toString()) await workspace.openResource(URI.file(configFileName).toString())
return return
} }
workspace.showMessage('Config file not found', 'warning') window.showMessage('Config file not found', 'warning')
} }
function isImplicitProjectConfigFile(configFileName: string): boolean { function isImplicitProjectConfigFile(configFileName: string): boolean {
@ -110,7 +109,7 @@ export class AutoFixCommand implements Command {
return return
} }
let file = client.serviceClient.toPath(document.uri) let file = client.serviceClient.toPath(document.uri)
let diagnostics = diagnosticManager.getDiagnostics(document.uri) let diagnostics = diagnosticManager.getDiagnostics(document.uri).slice() as Diagnostic[]
let missingDiagnostics = diagnostics.filter(o => o.code == 2307) let missingDiagnostics = diagnostics.filter(o => o.code == 2307)
if (missingDiagnostics.length) { if (missingDiagnostics.length) {
let names = missingDiagnostics.map(o => { let names = missingDiagnostics.map(o => {
@ -178,9 +177,14 @@ export class ConfigurePluginCommand implements Command {
public constructor( public constructor(
private readonly pluginManager: PluginManager, private readonly pluginManager: PluginManager,
) { } ) {}
public execute(pluginId: string, configuration: any): void { public execute(pluginId: string, configuration: any): void {
this.pluginManager.setConfiguration(pluginId, configuration) this.pluginManager.setConfiguration(pluginId, configuration)
} }
} }
export function registCommand(cmd: Command): Disposable {
let { id, execute } = cmd
return commands.registerCommand(id as string, execute, cmd)
}

View file

@ -2,9 +2,9 @@
* Copyright (c) Microsoft Corporation. All rights reserved. * Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { TextDocument } from 'coc.nvim'
import { CodeLensProvider } from 'coc.nvim'
import { CancellationToken, CodeLens, Emitter, Event, Range } from 'vscode-languageserver-protocol' import { CancellationToken, CodeLens, Emitter, Event, Range } from 'vscode-languageserver-protocol'
import { TextDocument } from 'vscode-languageserver-textdocument'
import { CodeLensProvider } from 'coc.nvim/lib/provider'
import * as Proto from '../protocol' import * as Proto from '../protocol'
import { ITypeScriptServiceClient } from '../typescriptService' import { ITypeScriptServiceClient } from '../typescriptService'
import { escapeRegExp } from '../utils/regexp' import { escapeRegExp } from '../utils/regexp'
@ -47,7 +47,7 @@ export abstract class TypeScriptBaseCodeLensProvider implements CodeLensProvider
public constructor( public constructor(
protected client: ITypeScriptServiceClient, protected client: ITypeScriptServiceClient,
private cachedResponse: CachedNavTreeResponse private cachedResponse: CachedNavTreeResponse
) { } ) {}
public get onDidChangeCodeLenses(): Event<void> { public get onDidChangeCodeLenses(): Event<void> {
return this.onDidChangeCodeLensesEmitter.event return this.onDidChangeCodeLensesEmitter.event

View file

@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { Uri, disposeAll, workspace } from 'coc.nvim' import { Uri, disposeAll, workspace } from 'coc.nvim'
import { CancellationTokenSource, CancellationToken, Emitter, Event, DidChangeTextDocumentParams, Disposable, TextDocumentContentChangeEvent } from 'vscode-languageserver-protocol' import { CancellationTokenSource, CancellationToken, Emitter, Event, DidChangeTextDocumentParams, Disposable, TextDocumentContentChangeEvent } from 'vscode-languageserver-protocol'
import { TextDocument } from 'vscode-languageserver-textdocument' import { TextDocument } from 'coc.nvim'
import Proto from '../protocol' import Proto from '../protocol'
import { ITypeScriptServiceClient } from '../typescriptService' import { ITypeScriptServiceClient } from '../typescriptService'
import API from '../utils/api' import API from '../utils/api'

View file

@ -1,22 +1,20 @@
import { commands, CompletionItemProvider, TextDocument, window, workspace } from 'coc.nvim'
/*--------------------------------------------------------------------------------------------- /*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved. * Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { CancellationToken, Command, CompletionContext, Range, CompletionItem, InsertTextFormat, MarkupContent, MarkupKind, Position, TextEdit, CompletionList } from 'vscode-languageserver-protocol' import { CancellationToken, Command, CompletionContext, CompletionItem, CompletionList, InsertTextFormat, MarkupContent, MarkupKind, Position, Range, TextEdit } from 'vscode-languageserver-protocol'
import { TextDocument } from 'vscode-languageserver-textdocument'
import { commands, workspace } from 'coc.nvim'
import { CompletionItemProvider } from 'coc.nvim/lib/provider'
import Proto from '../protocol' import Proto from '../protocol'
import * as PConst from '../protocol.const' import * as PConst from '../protocol.const'
import { ITypeScriptServiceClient, ServerResponse } from '../typescriptService' import { ITypeScriptServiceClient, ServerResponse } from '../typescriptService'
import API from '../utils/api' import API from '../utils/api'
import { applyCodeAction } from '../utils/codeAction' import { applyCodeAction } from '../utils/codeAction'
import { DotAccessorContext, convertCompletionEntry, getParameterListParts } from '../utils/completionItem' import { convertCompletionEntry, DotAccessorContext, getParameterListParts } from '../utils/completionItem'
import * as Previewer from '../utils/previewer' import * as Previewer from '../utils/previewer'
import SnippetString from '../utils/SnippetString'
import * as typeConverters from '../utils/typeConverters' import * as typeConverters from '../utils/typeConverters'
import TypingsStatus from '../utils/typingsStatus' import TypingsStatus from '../utils/typingsStatus'
import FileConfigurationManager, { SuggestOptions } from './fileConfigurationManager' import FileConfigurationManager, { SuggestOptions } from './fileConfigurationManager'
import SnippetString from '../utils/SnippetString'
// command center // command center
export interface CommandItem { export interface CommandItem {
@ -41,7 +39,7 @@ class ApplyCompletionCodeActionCommand implements CommandItem {
await applyCodeAction(this.client, codeActions[0]) await applyCodeAction(this.client, codeActions[0])
return return
} }
const idx = await workspace.showQuickpick(codeActions.map(o => o.description), 'Select code action to apply') const idx = await window.showQuickpick(codeActions.map(o => o.description), 'Select code action to apply')
if (idx < 0) return if (idx < 0) return
const action = codeActions[idx] const action = codeActions[idx]
await applyCodeAction(this.client, action) await applyCodeAction(this.client, action)
@ -62,7 +60,10 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP
) { ) {
this.setCompleteOption(languageId) this.setCompleteOption(languageId)
commands.register(new ApplyCompletionCodeActionCommand(this.client)) commands.registerCommand(ApplyCompletionCodeActionCommand.ID, async (codeActions) => {
let cmd = new ApplyCompletionCodeActionCommand(this.client)
await cmd.execute(codeActions)
})
workspace.onDidChangeConfiguration(_e => { workspace.onDidChangeConfiguration(_e => {
this.setCompleteOption(languageId) this.setCompleteOption(languageId)
}) })

View file

@ -2,15 +2,15 @@
* Copyright (c) Microsoft Corporation. All rights reserved. * Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { TextDocument } from 'coc.nvim'
import { DefinitionProvider, ImplementationProvider, TypeDefinitionProvider } from 'coc.nvim'
import { CancellationToken, Definition, Location, Position } from 'vscode-languageserver-protocol' import { CancellationToken, Definition, Location, Position } from 'vscode-languageserver-protocol'
import { TextDocument } from 'vscode-languageserver-textdocument'
import { DefinitionProvider, ImplementationProvider, TypeDefinitionProvider } from 'coc.nvim/lib/provider'
import * as Proto from '../protocol' import * as Proto from '../protocol'
import { ITypeScriptServiceClient } from '../typescriptService' import { ITypeScriptServiceClient } from '../typescriptService'
import * as typeConverters from '../utils/typeConverters' import * as typeConverters from '../utils/typeConverters'
export default class TypeScriptDefinitionProvider implements DefinitionProvider, TypeDefinitionProvider, ImplementationProvider { export default class TypeScriptDefinitionProvider implements DefinitionProvider, TypeDefinitionProvider, ImplementationProvider {
constructor(private client: ITypeScriptServiceClient) { } constructor(private client: ITypeScriptServiceClient) {}
protected async getSymbolLocations( protected async getSymbolLocations(
definitionType: 'definition' | 'implementation' | 'typeDefinition', definitionType: 'definition' | 'implementation' | 'typeDefinition',

View file

@ -2,8 +2,8 @@
* Copyright (c) Microsoft Corporation. All rights reserved. * Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { DiagnosticCollection, languages, workspace } from 'coc.nvim'
import { Diagnostic } from 'vscode-languageserver-protocol' import { Diagnostic } from 'vscode-languageserver-protocol'
import { workspace, languages, DiagnosticCollection } from 'coc.nvim'
import { ResourceMap } from './resourceMap' import { ResourceMap } from './resourceMap'
export class DiagnosticSet { export class DiagnosticSet {

View file

@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { CancellationToken, CompletionContext, CompletionItem, CompletionItemKind, CompletionList, Position, Range } from 'vscode-languageserver-protocol' import { CancellationToken, CompletionContext, CompletionItem, CompletionItemKind, CompletionList, Position, Range } from 'vscode-languageserver-protocol'
import { TextDocument } from 'vscode-languageserver-textdocument' import { TextDocument } from 'coc.nvim'
import { workspace } from 'coc.nvim' import { workspace } from 'coc.nvim'
import { ITypeScriptServiceClient } from '../typescriptService' import { ITypeScriptServiceClient } from '../typescriptService'
import API from '../utils/api' import API from '../utils/api'

View file

@ -2,16 +2,16 @@
* Copyright (c) Microsoft Corporation. All rights reserved. * Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { TextDocument } from 'coc.nvim'
import { DocumentHighlightProvider } from 'coc.nvim'
import { CancellationToken, DocumentHighlight, DocumentHighlightKind, Position } from 'vscode-languageserver-protocol' import { CancellationToken, DocumentHighlight, DocumentHighlightKind, Position } from 'vscode-languageserver-protocol'
import { TextDocument } from 'vscode-languageserver-textdocument' import { flatten } from '../../utils/arrays'
import { DocumentHighlightProvider } from 'coc.nvim/lib/provider'
import Proto from '../protocol' import Proto from '../protocol'
import { ITypeScriptServiceClient } from '../typescriptService' import { ITypeScriptServiceClient } from '../typescriptService'
import * as typeConverters from '../utils/typeConverters' import * as typeConverters from '../utils/typeConverters'
import { flatten } from '../../utils/arrays'
export default class TypeScriptDocumentHighlightProvider implements DocumentHighlightProvider { export default class TypeScriptDocumentHighlightProvider implements DocumentHighlightProvider {
public constructor(private readonly client: ITypeScriptServiceClient) { } public constructor(private readonly client: ITypeScriptServiceClient) {}
public async provideDocumentHighlights( public async provideDocumentHighlights(
resource: TextDocument, resource: TextDocument,

View file

@ -2,9 +2,9 @@
* Copyright (c) Microsoft Corporation. All rights reserved. * Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { TextDocument } from 'coc.nvim'
import { DocumentSymbolProvider } from 'coc.nvim'
import { CancellationToken, DocumentSymbol, Range, SymbolKind } from 'vscode-languageserver-protocol' import { CancellationToken, DocumentSymbol, Range, SymbolKind } from 'vscode-languageserver-protocol'
import { TextDocument } from 'vscode-languageserver-textdocument'
import { DocumentSymbolProvider } from 'coc.nvim/lib/provider'
import * as Proto from '../protocol' import * as Proto from '../protocol'
import * as PConst from '../protocol.const' import * as PConst from '../protocol.const'
import { ITypeScriptServiceClient } from '../typescriptService' import { ITypeScriptServiceClient } from '../typescriptService'
@ -46,7 +46,7 @@ const getSymbolKind = (kind: string): SymbolKind => {
} }
export default class TypeScriptDocumentSymbolProvider implements DocumentSymbolProvider { export default class TypeScriptDocumentSymbolProvider implements DocumentSymbolProvider {
public constructor(private readonly client: ITypeScriptServiceClient) { } public constructor(private readonly client: ITypeScriptServiceClient) {}
public async provideDocumentSymbols( public async provideDocumentSymbols(
resource: TextDocument, resource: TextDocument,

View file

@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { workspace, WorkspaceConfiguration, disposeAll } from 'coc.nvim' import { workspace, WorkspaceConfiguration, disposeAll } from 'coc.nvim'
import { CancellationToken, Disposable } from 'vscode-languageserver-protocol' import { CancellationToken, Disposable } from 'vscode-languageserver-protocol'
import { TextDocument } from 'vscode-languageserver-textdocument' import { TextDocument } from 'coc.nvim'
import Proto from '../protocol' import Proto from '../protocol'
import { ITypeScriptServiceClient } from '../typescriptService' import { ITypeScriptServiceClient } from '../typescriptService'
import API from '../utils/api' import API from '../utils/api'

View file

@ -3,17 +3,16 @@
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { TextDocument, workspace } from 'coc.nvim'
import { FoldingContext, FoldingRangeProvider } from 'coc.nvim'
import { CancellationToken } from 'vscode-jsonrpc' import { CancellationToken } from 'vscode-jsonrpc'
import { FoldingRange } from 'vscode-languageserver-types' import { FoldingRange } from 'vscode-languageserver-types'
import { TextDocument } from 'vscode-languageserver-textdocument'
import { FoldingContext, FoldingRangeProvider } from 'coc.nvim/lib/provider'
import { workspace } from 'coc.nvim'
import Proto from '../protocol' import Proto from '../protocol'
import { ITypeScriptServiceClient } from '../typescriptService' import { ITypeScriptServiceClient } from '../typescriptService'
import * as typeConverters from '../utils/typeConverters' import * as typeConverters from '../utils/typeConverters'
export default class TypeScriptFoldingProvider implements FoldingRangeProvider { export default class TypeScriptFoldingProvider implements FoldingRangeProvider {
public constructor(private readonly client: ITypeScriptServiceClient) { } public constructor(private readonly client: ITypeScriptServiceClient) {}
public async provideFoldingRanges( public async provideFoldingRanges(
document: TextDocument, document: TextDocument,

View file

@ -2,10 +2,9 @@
* Copyright (c) Microsoft Corporation. All rights reserved. * Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { workspace } from 'coc.nvim' import { TextDocument, workspace } from 'coc.nvim'
import { DocumentFormattingEditProvider, DocumentRangeFormattingEditProvider } from 'coc.nvim/lib/provider' import { DocumentFormattingEditProvider, DocumentRangeFormattingEditProvider } from 'coc.nvim'
import { CancellationToken, FormattingOptions, Position, Range, TextEdit } from 'vscode-languageserver-protocol' import { CancellationToken, FormattingOptions, Position, Range, TextEdit } from 'vscode-languageserver-protocol'
import { TextDocument } from 'vscode-languageserver-textdocument'
import * as Proto from '../protocol' import * as Proto from '../protocol'
import { ITypeScriptServiceClient } from '../typescriptService' import { ITypeScriptServiceClient } from '../typescriptService'
import * as typeConverters from '../utils/typeConverters' import * as typeConverters from '../utils/typeConverters'

View file

@ -2,16 +2,16 @@
* Copyright (c) Microsoft Corporation. All rights reserved. * Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { TextDocument } from 'coc.nvim'
import { HoverProvider } from 'coc.nvim'
import { CancellationToken, Hover, MarkedString, Position } from 'vscode-languageserver-protocol' import { CancellationToken, Hover, MarkedString, Position } from 'vscode-languageserver-protocol'
import { TextDocument } from 'vscode-languageserver-textdocument'
import { HoverProvider } from 'coc.nvim/lib/provider'
import * as Proto from '../protocol' import * as Proto from '../protocol'
import { ITypeScriptServiceClient } from '../typescriptService' import { ITypeScriptServiceClient } from '../typescriptService'
import { tagsMarkdownPreview } from '../utils/previewer' import { tagsMarkdownPreview } from '../utils/previewer'
import * as typeConverters from '../utils/typeConverters' import * as typeConverters from '../utils/typeConverters'
export default class TypeScriptHoverProvider implements HoverProvider { export default class TypeScriptHoverProvider implements HoverProvider {
public constructor(private readonly client: ITypeScriptServiceClient) { } public constructor(private readonly client: ITypeScriptServiceClient) {}
public async provideHover( public async provideHover(
document: TextDocument, document: TextDocument,

View file

@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { CancellationToken, CodeLens, Command, Location, Range } from 'vscode-languageserver-protocol' import { CancellationToken, CodeLens, Command, Location, Range } from 'vscode-languageserver-protocol'
import { TextDocument } from 'vscode-languageserver-textdocument' import { TextDocument } from 'coc.nvim'
import * as Proto from '../protocol' import * as Proto from '../protocol'
import * as PConst from '../protocol.const' import * as PConst from '../protocol.const'
import * as typeConverters from '../utils/typeConverters' import * as typeConverters from '../utils/typeConverters'

View file

@ -1,7 +1,7 @@
import { CodeActionProvider, workspace } from 'coc.nvim' import { CodeActionProvider, workspace } from 'coc.nvim'
import BufferSyncSupport from './bufferSyncSupport' import BufferSyncSupport from './bufferSyncSupport'
import { Range, CodeActionContext, CancellationToken, CodeAction } from 'vscode-languageserver-protocol' import { Range, CodeActionContext, CancellationToken, CodeAction } from 'vscode-languageserver-protocol'
import { TextDocument } from 'vscode-languageserver-textdocument' import { TextDocument } from 'coc.nvim'
import { nodeModules } from '../utils/helper' import { nodeModules } from '../utils/helper'
import { WorkspaceEdit, Command, TextEdit } from 'vscode-languageserver-types' import { WorkspaceEdit, Command, TextEdit } from 'vscode-languageserver-types'

View file

@ -1,27 +1,14 @@
import { Uri, commands } from 'coc.nvim' import { CodeActionProvider, commands, TextDocument, Uri } from 'coc.nvim'
import { Command } from 'coc.nvim/lib/commands'
import { CodeActionProvider } from 'coc.nvim/lib/provider'
import { CancellationToken, CodeAction, CodeActionContext, CodeActionKind, Range } from 'vscode-languageserver-protocol' import { CancellationToken, CodeAction, CodeActionContext, CodeActionKind, Range } from 'vscode-languageserver-protocol'
import { TextDocument } from 'vscode-languageserver-textdocument'
import { ITypeScriptServiceClient } from '../typescriptService' import { ITypeScriptServiceClient } from '../typescriptService'
import { installModules } from '../utils/modules' import { installModules } from '../utils/modules'
class InstallModuleCommand implements Command {
public static readonly ID = '_tsserver.installModule'
public readonly id = InstallModuleCommand.ID
public async execute(
uri: string,
name: string
): Promise<void> {
await installModules(uri, [name])
}
}
export default class InstallModuleProvider implements CodeActionProvider { export default class InstallModuleProvider implements CodeActionProvider {
constructor(private readonly client: ITypeScriptServiceClient) { constructor(private readonly client: ITypeScriptServiceClient) {
commands.register(new InstallModuleCommand(), true) commands.registerCommand('_tsserver.installModule', async (uri: string, name: string) => {
await installModules(uri, [name])
})
} }
public async provideCodeActions( public async provideCodeActions(
@ -45,7 +32,7 @@ export default class InstallModuleProvider implements CodeActionProvider {
let title = `install ${name}` let title = `install ${name}`
let command = { let command = {
title: `install ${name}`, title: `install ${name}`,
command: InstallModuleCommand.ID, command: '_tsserver.installModule',
arguments: [document.uri, name] arguments: [document.uri, name]
} }
let codeAction = CodeAction.create(title, command, CodeActionKind.QuickFix) let codeAction = CodeAction.create(title, command, CodeActionKind.QuickFix)

View file

@ -2,11 +2,9 @@
* Copyright (c) Microsoft Corporation. All rights reserved. * Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { commands, workspace } from 'coc.nvim' import { CodeActionProvider, TextDocument, workspace } from 'coc.nvim'
import { Command } from 'coc.nvim/lib/commands'
import { CodeActionProvider } from 'coc.nvim/lib/provider'
import { CancellationToken, CodeAction, CodeActionContext, CodeActionKind, Diagnostic, Range } from 'vscode-languageserver-protocol' import { CancellationToken, CodeAction, CodeActionContext, CodeActionKind, Diagnostic, Range } from 'vscode-languageserver-protocol'
import { TextDocument } from 'vscode-languageserver-textdocument' import { Command, registCommand } from '../commands'
import * as Proto from '../protocol' import * as Proto from '../protocol'
import { ITypeScriptServiceClient } from '../typescriptService' import { ITypeScriptServiceClient } from '../typescriptService'
import API from '../utils/api' import API from '../utils/api'
@ -21,7 +19,7 @@ class ApplyCodeActionCommand implements Command {
constructor( constructor(
private readonly client: ITypeScriptServiceClient, private readonly client: ITypeScriptServiceClient,
private readonly formattingConfigurationManager: FileConfigurationManager private readonly formattingConfigurationManager: FileConfigurationManager
) { } ) {}
public async execute(action: Proto.CodeFixAction): Promise<boolean> { public async execute(action: Proto.CodeFixAction): Promise<boolean> {
return applyCodeActionCommands(this.client, action) return applyCodeActionCommands(this.client, action)
@ -35,7 +33,7 @@ class ApplyFixAllCodeAction implements Command {
constructor( constructor(
private readonly client: ITypeScriptServiceClient, private readonly client: ITypeScriptServiceClient,
private readonly formattingConfigurationManager: FileConfigurationManager private readonly formattingConfigurationManager: FileConfigurationManager
) { } ) {}
public async execute( public async execute(
document: TextDocument, document: TextDocument,
@ -100,7 +98,7 @@ class DiagnosticsSet {
private constructor( private constructor(
private readonly _values: Map<string, Diagnostic> private readonly _values: Map<string, Diagnostic>
) { } ) {}
public get values(): Iterable<Diagnostic> { public get values(): Iterable<Diagnostic> {
return this._values.values() return this._values.values()
@ -110,7 +108,7 @@ class DiagnosticsSet {
class SupportedCodeActionProvider { class SupportedCodeActionProvider {
private _supportedCodeActions?: Thenable<Set<number>> private _supportedCodeActions?: Thenable<Set<number>>
public constructor(private readonly client: ITypeScriptServiceClient) { } public constructor(private readonly client: ITypeScriptServiceClient) {}
public async getFixableDiagnosticsForContext( public async getFixableDiagnosticsForContext(
context: CodeActionContext context: CodeActionContext
@ -148,13 +146,8 @@ export default class TypeScriptQuickFixProvider implements CodeActionProvider {
private readonly client: ITypeScriptServiceClient, private readonly client: ITypeScriptServiceClient,
private readonly formattingConfigurationManager: FileConfigurationManager private readonly formattingConfigurationManager: FileConfigurationManager
) { ) {
commands.register( registCommand(new ApplyCodeActionCommand(client, formattingConfigurationManager))
new ApplyCodeActionCommand(client, formattingConfigurationManager) registCommand(new ApplyFixAllCodeAction(client, formattingConfigurationManager))
)
commands.register(
new ApplyFixAllCodeAction(client, formattingConfigurationManager)
)
this.supportedCodeActionProvider = new SupportedCodeActionProvider(client) this.supportedCodeActionProvider = new SupportedCodeActionProvider(client)
} }

View file

@ -1,12 +1,10 @@
import { CodeActionProvider, CodeActionProviderMetadata, commands, TextDocument, window, workspace } from 'coc.nvim'
/*--------------------------------------------------------------------------------------------- /*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved. * Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { CancellationToken, CodeAction, CodeActionContext, CodeActionKind, Range, WorkspaceEdit } from 'vscode-languageserver-protocol' import { CancellationToken, CodeAction, CodeActionContext, CodeActionKind, Range, WorkspaceEdit } from 'vscode-languageserver-protocol'
import { TextDocument } from 'vscode-languageserver-textdocument' import { Command, registCommand } from '../commands'
import { Command } from 'coc.nvim/lib/commands'
import { CodeActionProvider, CodeActionProviderMetadata } from 'coc.nvim/lib/provider'
import { workspace, commands } from 'coc.nvim'
import Proto from '../protocol' import Proto from '../protocol'
import { ITypeScriptServiceClient } from '../typescriptService' import { ITypeScriptServiceClient } from '../typescriptService'
import * as typeConverters from '../utils/typeConverters' import * as typeConverters from '../utils/typeConverters'
@ -22,7 +20,7 @@ class ApplyRefactoringCommand implements Command {
public static readonly ID = '_typescript.applyRefactoring' public static readonly ID = '_typescript.applyRefactoring'
public readonly id = ApplyRefactoringCommand.ID public readonly id = ApplyRefactoringCommand.ID
constructor(private readonly client: ITypeScriptServiceClient) { } constructor(private readonly client: ITypeScriptServiceClient) {}
public async execute( public async execute(
document: TextDocument, document: TextDocument,
@ -72,7 +70,7 @@ class SelectRefactorCommand implements Command {
public static readonly ID = '_typescript.selectRefactoring' public static readonly ID = '_typescript.selectRefactoring'
public readonly id = SelectRefactorCommand.ID public readonly id = SelectRefactorCommand.ID
constructor(private readonly doRefactoring: ApplyRefactoringCommand) { } constructor(private readonly doRefactoring: ApplyRefactoringCommand) {}
public async execute( public async execute(
document: TextDocument, document: TextDocument,
@ -81,7 +79,7 @@ class SelectRefactorCommand implements Command {
range: Range range: Range
): Promise<boolean> { ): Promise<boolean> {
let { actions } = info let { actions } = info
const idx = actions.length == 1 ? 0 : await workspace.showQuickpick( const idx = actions.length == 1 ? 0 : await window.showQuickpick(
actions.map(action => action.description || action.name) actions.map(action => action.description || action.name)
) )
if (idx == -1) return false if (idx == -1) return false
@ -106,10 +104,9 @@ export default class TypeScriptRefactorProvider implements CodeActionProvider {
private readonly client: ITypeScriptServiceClient, private readonly client: ITypeScriptServiceClient,
private readonly formattingOptionsManager: FormattingOptionsManager, private readonly formattingOptionsManager: FormattingOptionsManager,
) { ) {
const doRefactoringCommand = commands.register( const doRefactoringCommand = new ApplyRefactoringCommand(this.client)
new ApplyRefactoringCommand(this.client) registCommand(doRefactoringCommand)
) registCommand(new SelectRefactorCommand(doRefactoringCommand))
commands.register(new SelectRefactorCommand(doRefactoringCommand))
} }
public static readonly metadata: CodeActionProviderMetadata = { public static readonly metadata: CodeActionProviderMetadata = {

View file

@ -2,9 +2,9 @@
* Copyright (c) Microsoft Corporation. All rights reserved. * Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { TextDocument } from 'coc.nvim'
import { ReferenceContext, ReferenceProvider } from 'coc.nvim'
import { CancellationToken, Location, Position } from 'vscode-languageserver-protocol' import { CancellationToken, Location, Position } from 'vscode-languageserver-protocol'
import { TextDocument } from 'vscode-languageserver-textdocument'
import { ReferenceContext, ReferenceProvider } from 'coc.nvim/lib/provider'
import { ITypeScriptServiceClient } from '../typescriptService' import { ITypeScriptServiceClient } from '../typescriptService'
import * as typeConverters from '../utils/typeConverters' import * as typeConverters from '../utils/typeConverters'

View file

@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { CancellationToken, CodeLens, Range } from 'vscode-languageserver-protocol' import { CancellationToken, CodeLens, Range } from 'vscode-languageserver-protocol'
import { TextDocument } from 'vscode-languageserver-textdocument' import { TextDocument } from 'coc.nvim'
import * as Proto from '../protocol' import * as Proto from '../protocol'
import * as PConst from '../protocol.const' import * as PConst from '../protocol.const'
import * as typeConverters from '../utils/typeConverters' import * as typeConverters from '../utils/typeConverters'

View file

@ -5,7 +5,7 @@
import { Uri, RenameProvider } from 'coc.nvim' import { Uri, RenameProvider } from 'coc.nvim'
import path from 'path' import path from 'path'
import { CancellationToken, Position, Range, TextEdit, WorkspaceEdit } from 'vscode-languageserver-protocol' import { CancellationToken, Position, Range, TextEdit, WorkspaceEdit } from 'vscode-languageserver-protocol'
import { TextDocument } from 'vscode-languageserver-textdocument' import { TextDocument } from 'coc.nvim'
import * as Proto from '../protocol' import * as Proto from '../protocol'
import { ITypeScriptServiceClient, ServerResponse } from '../typescriptService' import { ITypeScriptServiceClient, ServerResponse } from '../typescriptService'
import API from '../utils/api' import API from '../utils/api'

View file

@ -2,9 +2,9 @@
* Copyright (c) Microsoft Corporation. All rights reserved. * Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { TextDocument } from 'coc.nvim'
import { SignatureHelpProvider } from 'coc.nvim'
import { CancellationToken, Position, SignatureHelp, SignatureInformation } from 'vscode-languageserver-protocol' import { CancellationToken, Position, SignatureHelp, SignatureInformation } from 'vscode-languageserver-protocol'
import { TextDocument } from 'vscode-languageserver-textdocument'
import { SignatureHelpProvider } from 'coc.nvim/lib/provider'
import * as Proto from '../protocol' import * as Proto from '../protocol'
import { ITypeScriptServiceClient } from '../typescriptService' import { ITypeScriptServiceClient } from '../typescriptService'
import * as Previewer from '../utils/previewer' import * as Previewer from '../utils/previewer'
@ -13,7 +13,7 @@ import * as typeConverters from '../utils/typeConverters'
export default class TypeScriptSignatureHelpProvider implements SignatureHelpProvider { export default class TypeScriptSignatureHelpProvider implements SignatureHelpProvider {
public static readonly triggerCharacters = ['(', ',', '<'] public static readonly triggerCharacters = ['(', ',', '<']
public constructor(private readonly client: ITypeScriptServiceClient) { } public constructor(private readonly client: ITypeScriptServiceClient) {}
public async provideSignatureHelp( public async provideSignatureHelp(
document: TextDocument, document: TextDocument,

View file

@ -6,7 +6,7 @@
import * as Proto from '../protocol' import * as Proto from '../protocol'
import { ITypeScriptServiceClient } from '../typescriptService' import { ITypeScriptServiceClient } from '../typescriptService'
import { Range, Position, CancellationToken } from 'vscode-languageserver-protocol' import { Range, Position, CancellationToken } from 'vscode-languageserver-protocol'
import { TextDocument } from 'vscode-languageserver-textdocument' import { TextDocument } from 'coc.nvim'
import * as typeConverters from '../utils/typeConverters' import * as typeConverters from '../utils/typeConverters'
import { SelectionRangeProvider } from 'coc.nvim' import { SelectionRangeProvider } from 'coc.nvim'

View file

@ -2,9 +2,9 @@
* Copyright (c) Microsoft Corporation. All rights reserved. * Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { TextDocument } from 'coc.nvim'
import { CompletionItemProvider } from 'coc.nvim'
import { CancellationToken, CompletionContext, CompletionItem, Position } from 'vscode-languageserver-protocol' import { CancellationToken, CompletionContext, CompletionItem, Position } from 'vscode-languageserver-protocol'
import { TextDocument } from 'vscode-languageserver-textdocument'
import { CompletionItemProvider } from 'coc.nvim/lib/provider'
import * as Proto from '../protocol' import * as Proto from '../protocol'
import { ITypeScriptServiceClient } from '../typescriptService' import { ITypeScriptServiceClient } from '../typescriptService'
import * as typeConverters from '../utils/typeConverters' import * as typeConverters from '../utils/typeConverters'
@ -12,7 +12,7 @@ import * as typeConverters from '../utils/typeConverters'
export default class TypeScriptTagCompletion implements CompletionItemProvider { export default class TypeScriptTagCompletion implements CompletionItemProvider {
constructor( constructor(
private readonly client: ITypeScriptServiceClient private readonly client: ITypeScriptServiceClient
) { } ) {}
public async provideCompletionItems( public async provideCompletionItems(
document: TextDocument, document: TextDocument,

View file

@ -1,15 +1,14 @@
import { disposeAll, TextDocument, Uri, window, workspace } from 'coc.nvim'
/*--------------------------------------------------------------------------------------------- /*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved. * Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { Disposable, WorkspaceEdit, CancellationToken } from 'vscode-languageserver-protocol' import { CancellationToken, Disposable, WorkspaceEdit } from 'vscode-languageserver-protocol'
import { TextDocument } from 'vscode-languageserver-textdocument'
import { Uri, disposeAll, workspace } from 'coc.nvim'
import * as Proto from '../protocol' import * as Proto from '../protocol'
import { ITypeScriptServiceClient } from '../typescriptService' import { ITypeScriptServiceClient } from '../typescriptService'
import { Mutex } from '../utils/mutex'
import * as typeConverters from '../utils/typeConverters' import * as typeConverters from '../utils/typeConverters'
import FileConfigurationManager from './fileConfigurationManager' import FileConfigurationManager from './fileConfigurationManager'
import { Mutex } from '../utils/mutex'
function wait(ms: number): Promise<void> { function wait(ms: number): Promise<void> {
return new Promise(resolve => { return new Promise(resolve => {
@ -81,7 +80,7 @@ export default class UpdateImportsOnFileRenameHandler {
} }
private async promptUser(newResource: Uri): Promise<boolean> { private async promptUser(newResource: Uri): Promise<boolean> {
return await workspace.showPrompt(`Update imports for moved file: ${newResource.fsPath}?`) return await window.showPrompt(`Update imports for moved file: ${newResource.fsPath}?`)
} }
private async getEditsForFileRename(document: TextDocument, oldFile: string, newFile: string): Promise<WorkspaceEdit> { private async getEditsForFileRename(document: TextDocument, oldFile: string, newFile: string): Promise<WorkspaceEdit> {

View file

@ -1,4 +1,4 @@
import { disposeAll, commands, StatusBarItem, TaskOptions, Uri, workspace } from 'coc.nvim' import { commands, disposeAll, StatusBarItem, TaskOptions, Uri, window, workspace } from 'coc.nvim'
import path from 'path' import path from 'path'
import { Disposable, Location } from 'vscode-languageserver-protocol' import { Disposable, Location } from 'vscode-languageserver-protocol'
import TypeScriptServiceClient from '../typescriptServiceClient' import TypeScriptServiceClient from '../typescriptServiceClient'
@ -30,7 +30,7 @@ export default class WatchProject implements Disposable {
public constructor( public constructor(
private client: TypeScriptServiceClient private client: TypeScriptServiceClient
) { ) {
this.statusItem = workspace.createStatusBarItem(1, { progress: true }) this.statusItem = window.createStatusBarItem(1, { progress: true })
let task = this.task = workspace.createTask('TSC') let task = this.task = workspace.createTask('TSC')
this.disposables.push(commands.registerCommand(WatchProject.id, async () => { this.disposables.push(commands.registerCommand(WatchProject.id, async () => {
let opts = this.options = await this.getOptions() let opts = this.options = await this.getOptions()
@ -38,7 +38,7 @@ export default class WatchProject implements Disposable {
})) }))
task.onExit(code => { task.onExit(code => {
if (code != 0) { if (code != 0) {
workspace.showMessage(`TSC exit with code ${code}`, 'warning') window.showMessage(`TSC exit with code ${code}`, 'warning')
} }
this.onStop() this.onStop()
}) })
@ -48,7 +48,7 @@ export default class WatchProject implements Disposable {
} }
}) })
task.onStderr(lines => { task.onStderr(lines => {
workspace.showMessage(`TSC error: ` + lines.join('\n'), 'error') window.showMessage(`TSC error: ` + lines.join('\n'), 'error')
}) })
this.disposables.push(Disposable.create(() => { this.disposables.push(Disposable.create(() => {
task.dispose() task.dispose()
@ -114,12 +114,12 @@ export default class WatchProject implements Disposable {
public async getOptions(): Promise<TaskOptions> { public async getOptions(): Promise<TaskOptions> {
let { tscPath } = this.client let { tscPath } = this.client
if (!tscPath) { if (!tscPath) {
workspace.showMessage(`Local & global tsc not found`, 'error') window.showMessage(`Local & global tsc not found`, 'error')
return return
} }
let find = await workspace.findUp(['tsconfig.json']) let find = await workspace.findUp(['tsconfig.json'])
if (!find) { if (!find) {
workspace.showMessage('tsconfig.json not found!', 'error') window.showMessage('tsconfig.json not found!', 'error')
return return
} }
let root = path.dirname(find) let root = path.dirname(find)

View file

@ -2,13 +2,13 @@
* Copyright (c) Microsoft Corporation. All rights reserved. * Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import {CancellationToken, Range, SymbolInformation, SymbolKind} from 'vscode-languageserver-protocol' import { workspace } from 'coc.nvim'
import {WorkspaceSymbolProvider} from 'coc.nvim/lib/provider' import { WorkspaceSymbolProvider } from 'coc.nvim'
import {workspace} from 'coc.nvim' import { CancellationToken, Range, SymbolInformation, SymbolKind } from 'vscode-languageserver-protocol'
import * as Proto from '../protocol' import * as Proto from '../protocol'
import {ITypeScriptServiceClient} from '../typescriptService' import { ITypeScriptServiceClient } from '../typescriptService'
import * as typeConverters from '../utils/typeConverters'
import API from '../utils/api' import API from '../utils/api'
import * as typeConverters from '../utils/typeConverters'
function getSymbolKind(item: Proto.NavtoItem): SymbolKind { function getSymbolKind(item: Proto.NavtoItem): SymbolKind {
switch (item.kind) { switch (item.kind) {

View file

@ -2,12 +2,13 @@
* Copyright (c) Microsoft Corporation. All rights reserved. * Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { DiagnosticKind, disposeAll, languages, Uri, workspace } from 'coc.nvim' import { disposeAll, languages, Uri, workspace } from 'coc.nvim'
import path from 'path' import path from 'path'
import { CodeActionKind, Diagnostic, DiagnosticSeverity, Disposable, TextDocument } from 'vscode-languageserver-protocol' import { CodeActionKind, Diagnostic, DiagnosticSeverity, Disposable, TextDocument } from 'vscode-languageserver-protocol'
import { CachedNavTreeResponse } from './features/baseCodeLensProvider' import { CachedNavTreeResponse } from './features/baseCodeLensProvider'
import CompletionItemProvider from './features/completionItemProvider' import CompletionItemProvider from './features/completionItemProvider'
import DefinitionProvider from './features/definitionProvider' import DefinitionProvider from './features/definitionProvider'
import { DiagnosticKind } from './features/diagnostics'
import DirectiveCommentCompletionProvider from './features/directiveCommentCompletions' import DirectiveCommentCompletionProvider from './features/directiveCommentCompletions'
import DocumentHighlight from './features/documentHighlight' import DocumentHighlight from './features/documentHighlight'
import DocumentSymbolProvider from './features/documentSymbol' import DocumentSymbolProvider from './features/documentSymbol'

View file

@ -2,15 +2,14 @@
* Copyright (c) Microsoft Corporation. All rights reserved. * Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { workspace, CodeActionProvider, CodeActionProviderMetadata } from 'coc.nvim' import { CodeActionProvider, CodeActionProviderMetadata, TextDocument, workspace } from 'coc.nvim'
import { CancellationToken, Range, CodeActionContext, WorkspaceEdit, CodeActionKind, CodeAction, TextEdit } from 'vscode-languageserver-protocol' import { CancellationToken, CodeAction, CodeActionContext, CodeActionKind, Range, TextEdit, WorkspaceEdit } from 'vscode-languageserver-protocol'
import { TextDocument } from 'vscode-languageserver-textdocument'
import { Command } from './commands'
import Proto from './protocol'
import * as typeconverts from './utils/typeConverters'
import FileConfigurationManager from './features/fileConfigurationManager'
import TypeScriptServiceClient from './typescriptServiceClient'
import TsserverService from '../server' import TsserverService from '../server'
import { Command } from './commands'
import FileConfigurationManager from './features/fileConfigurationManager'
import Proto from './protocol'
import TypeScriptServiceClient from './typescriptServiceClient'
import * as typeconverts from './utils/typeConverters'
export class OrganizeImportsCommand implements Command { export class OrganizeImportsCommand implements Command {
public readonly id: string = 'tsserver.organizeImports' public readonly id: string = 'tsserver.organizeImports'

View file

@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import cp from 'child_process' import cp from 'child_process'
import { disposeAll, ServiceStat, Uri, workspace } from 'coc.nvim' import { ServiceStat, Uri, window, workspace } from 'coc.nvim'
import fs from 'fs' import fs from 'fs'
import os from 'os' import os from 'os'
import path from 'path' import path from 'path'
@ -270,7 +270,7 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
public ensureServiceStarted(): void { public ensureServiceStarted(): void {
if (!this.servicePromise) { if (!this.servicePromise) {
this.startService().catch(err => { this.startService().catch(err => {
workspace.showMessage(`TSServer start failed: ${err.message}`, 'error') window.showMessage(`TSServer start failed: ${err.message}`, 'error')
this.error(`Service start failed: ${err.stack}`) this.error(`Service start failed: ${err.stack}`)
}) })
} }
@ -285,9 +285,9 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
} }
if (!currentVersion || !currentVersion.isValid) { if (!currentVersion || !currentVersion.isValid) {
if (this.configuration.globalTsdk) { if (this.configuration.globalTsdk) {
workspace.showMessage(`Can not find typescript module, in 'tsserver.tsdk': ${this.configuration.globalTsdk}`, 'error') window.showMessage(`Can not find typescript module, in 'tsserver.tsdk': ${this.configuration.globalTsdk}`, 'error')
} else { } else {
workspace.showMessage(`Can not find typescript module, run ':CocInstall coc-tsserver' to fix it!`, 'error') window.showMessage(`Can not find typescript module, run ':CocInstall coc-tsserver' to fix it!`, 'error')
} }
return return
} }
@ -335,7 +335,7 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
this.lastError = err this.lastError = err
this.error('TSServer errored with error.', err) this.error('TSServer errored with error.', err)
this.error(`TSServer log file: ${this.tsServerLogFile || ''}`) this.error(`TSServer log file: ${this.tsServerLogFile || ''}`)
workspace.showMessage(`TSServer errored with error. ${err.message}`, 'error') window.showMessage(`TSServer errored with error. ${err.message}`, 'error')
this.serviceExited(false) this.serviceExited(false)
}) })
handle.onExit((code: any) => { handle.onExit((code: any) => {
@ -371,7 +371,7 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
public async openTsServerLogFile(): Promise<boolean> { public async openTsServerLogFile(): Promise<boolean> {
const isRoot = process.getuid && process.getuid() == 0 const isRoot = process.getuid && process.getuid() == 0
let echoErr = (msg: string) => { let echoErr = (msg: string) => {
workspace.showMessage(msg, 'error') window.showMessage(msg, 'error')
} }
if (isRoot) { if (isRoot) {
echoErr('Log disabled for root user.') echoErr('Log disabled for root user.')
@ -463,10 +463,10 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
if (diff < 10 * 1000 /* 10 seconds */) { if (diff < 10 * 1000 /* 10 seconds */) {
this.lastStart = Date.now() this.lastStart = Date.now()
startService = false startService = false
workspace.showMessage('The TypeScript language service died 5 times right after it got started.', 'error') // tslint:disable-line window.showMessage('The TypeScript language service died 5 times right after it got started.', 'error') // tslint:disable-line
} else if (diff < 60 * 1000 /* 1 Minutes */) { } else if (diff < 60 * 1000 /* 1 Minutes */) {
this.lastStart = Date.now() this.lastStart = Date.now()
workspace.showMessage('The TypeScript language service died unexpectedly 5 times in the last 5 Minutes.', 'error') // tslint:disable-line window.showMessage('The TypeScript language service died unexpectedly 5 times in the last 5 Minutes.', 'error') // tslint:disable-line
} }
} }
if (startService) { if (startService) {

View file

@ -2,21 +2,21 @@
* Copyright (c) Microsoft Corporation. All rights reserved. * Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { Uri, DiagnosticKind, disposeAll, workspace, languages } from 'coc.nvim' import { disposeAll, languages, TextDocument, Uri, workspace } from 'coc.nvim'
import { Range, Diagnostic, DiagnosticSeverity, Disposable, Position, CancellationToken, DiagnosticRelatedInformation } from 'vscode-languageserver-protocol' import { CancellationToken, Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity, Disposable, Position, Range } from 'vscode-languageserver-protocol'
import { flatten } from '../utils/arrays'
import { PluginManager } from '../utils/plugins'
import { DiagnosticKind } from './features/diagnostics'
import FileConfigurationManager from './features/fileConfigurationManager'
import WatchBuild from './features/watchBuild'
import WorkspaceSymbolProvider from './features/workspaceSymbols'
import LanguageProvider from './languageProvider' import LanguageProvider from './languageProvider'
import * as Proto from './protocol' import * as Proto from './protocol'
import * as PConst from './protocol.const' import * as PConst from './protocol.const'
import FileConfigurationManager from './features/fileConfigurationManager'
import TypeScriptServiceClient from './typescriptServiceClient' import TypeScriptServiceClient from './typescriptServiceClient'
import { DiagnosticLanguage, LanguageDescription } from './utils/languageDescription' import { DiagnosticLanguage, LanguageDescription } from './utils/languageDescription'
import * as typeConverters from './utils/typeConverters' import * as typeConverters from './utils/typeConverters'
import TypingsStatus, { AtaProgressReporter } from './utils/typingsStatus' import TypingsStatus, { AtaProgressReporter } from './utils/typingsStatus'
import { PluginManager } from '../utils/plugins'
import { flatten } from '../utils/arrays'
import WatchBuild from './features/watchBuild'
import WorkspaceSymbolProvider from './features/workspaceSymbols'
import { TextDocument } from 'vscode-languageserver-textdocument'
// Style check diagnostics that can be reported as warnings // Style check diagnostics that can be reported as warnings
const styleCheckDiagnostics = [ const styleCheckDiagnostics = [

View file

@ -1,9 +1,4 @@
/*--------------------------------------------------------------------------------------------- import { OutputChannel, window } from 'coc.nvim'
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { OutputChannel, workspace } from 'coc.nvim'
import * as is from './is' import * as is from './is'
export default class Logger { export default class Logger {
@ -14,7 +9,7 @@ export default class Logger {
if (this._channel) { if (this._channel) {
return this._channel return this._channel
} }
this._channel = workspace.createOutputChannel('tsserver') this._channel = window.createOutputChannel('tsserver')
return this._channel return this._channel
} }

View file

@ -1,5 +1,5 @@
import { exec } from 'child_process' import { exec } from 'child_process'
import { workspace, Uri } from 'coc.nvim' import { Uri, window, workspace } from 'coc.nvim'
import fs from 'fs' import fs from 'fs'
import path from 'path' import path from 'path'
@ -28,12 +28,6 @@ async function getManager(): Promise<string> {
return res.endsWith('yarn.lock') ? 'yarn' : 'npm' return res.endsWith('yarn.lock') ? 'yarn' : 'npm'
} }
async function getRoot(): Promise<string | null> {
let res = await workspace.findUp(['package.json'])
if (!res) return null
return path.dirname(res)
}
export async function moduleExists(name: string): Promise<boolean> { export async function moduleExists(name: string): Promise<boolean> {
try { try {
let content = await runCommand(`npm info ${name} --json`, process.cwd()) let content = await runCommand(`npm info ${name} --json`, process.cwd())
@ -76,11 +70,11 @@ export async function installModules(uri: string, names: string[]): Promise<void
let workspaceFolder = workspace.getWorkspaceFolder(uri) let workspaceFolder = workspace.getWorkspaceFolder(uri)
let root = workspaceFolder ? Uri.parse(workspaceFolder.uri).fsPath : undefined let root = workspaceFolder ? Uri.parse(workspaceFolder.uri).fsPath : undefined
if (!root || !fs.existsSync(path.join(root, 'package.json'))) { if (!root || !fs.existsSync(path.join(root, 'package.json'))) {
workspace.showMessage(`package.json not found from workspaceFolder: ${root}`, 'error') window.showMessage(`package.json not found from workspaceFolder: ${root}`, 'error')
return return
} }
let arr = names.concat(names.map(s => `@types/${s}`)) let arr = names.concat(names.map(s => `@types/${s}`))
let statusItem = workspace.createStatusBarItem(99, { progress: true }) let statusItem = window.createStatusBarItem(99, { progress: true })
statusItem.text = `Checking module ${arr.join(' ')}` statusItem.text = `Checking module ${arr.join(' ')}`
statusItem.show() statusItem.show()
let exists = await Promise.all(arr.map(name => { let exists = await Promise.all(arr.map(name => {
@ -101,9 +95,9 @@ export async function installModules(uri: string, names: string[]): Promise<void
await runCommand(cmd, root) await runCommand(cmd, root)
} catch (e) { } catch (e) {
statusItem.dispose() statusItem.dispose()
workspace.showMessage(`Install error ${e.message}`, 'error') window.showMessage(`Install error ${e.message}`, 'error')
return return
} }
statusItem.dispose() statusItem.dispose()
workspace.showMessage(`Installed: ${exists.join(' ')}`, 'more') window.showMessage(`Installed: ${exists.join(' ')}`, 'more')
} }

View file

@ -1,10 +1,10 @@
import { StatusBarItem, window } from 'coc.nvim'
/*--------------------------------------------------------------------------------------------- /*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved. * Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { Disposable } from 'vscode-languageserver-protocol' import { Disposable } from 'vscode-languageserver-protocol'
import { ITypeScriptServiceClient } from '../typescriptService' import { ITypeScriptServiceClient } from '../typescriptService'
import { workspace, StatusBarItem } from 'coc.nvim'
const typingsInstallTimeout = 30 * 1000 const typingsInstallTimeout = 30 * 1000
@ -67,7 +67,7 @@ export class AtaProgressReporter {
private statusItem: StatusBarItem private statusItem: StatusBarItem
constructor(client: ITypeScriptServiceClient) { constructor(client: ITypeScriptServiceClient) {
this.statusItem = workspace.createStatusBarItem(10, { progress: true }) this.statusItem = window.createStatusBarItem(10, { progress: true })
const disposables: Disposable[] = [] const disposables: Disposable[] = []
disposables.push(client.onDidBeginInstallTypings(e => this._onBegin(e.eventId))) disposables.push(client.onDidBeginInstallTypings(e => this._onBegin(e.eventId)))
disposables.push(client.onDidEndInstallTypings(e => this._onEndOrTimeout(e.eventId))) disposables.push(client.onDidEndInstallTypings(e => this._onEndOrTimeout(e.eventId)))
@ -113,7 +113,7 @@ export class AtaProgressReporter {
private onTypesInstallerInitializationFailed() { // tslint:disable-line private onTypesInstallerInitializationFailed() { // tslint:disable-line
this.statusItem.hide() this.statusItem.hide()
if (!this._invalid) { if (!this._invalid) {
workspace.showMessage('Could not install typings files for JavaScript language features. Please ensure that NPM is installed', 'error') window.showMessage('Could not install typings files for JavaScript language features. Please ensure that NPM is installed', 'error')
} }
this._invalid = true this._invalid = true
} }

View file

@ -1,10 +1,10 @@
import { Uri, window, workspace } from 'coc.nvim'
/*--------------------------------------------------------------------------------------------- /*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved. * Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import fs from 'fs' import fs from 'fs'
import path from 'path' import path from 'path'
import { workspace, Uri } from 'coc.nvim'
import API from './api' import API from './api'
import { TypeScriptServiceConfiguration } from './configuration' import { TypeScriptServiceConfiguration } from './configuration'
declare var __webpack_require__: any declare var __webpack_require__: any
@ -88,7 +88,7 @@ const MODULE_FOLDERS = ['node_modules/typescript/lib', '.vscode/pnpify/typescrip
export class TypeScriptVersionProvider { export class TypeScriptVersionProvider {
public constructor(private configuration: TypeScriptServiceConfiguration) { } public constructor(private configuration: TypeScriptServiceConfiguration) {}
public updateConfiguration( public updateConfiguration(
configuration: TypeScriptServiceConfiguration configuration: TypeScriptServiceConfiguration
@ -131,7 +131,7 @@ export class TypeScriptVersionProvider {
'') '')
return bundledVersion return bundledVersion
} catch (e) { } catch (e) {
workspace.showMessage('Bundled typescript module not found', 'error') window.showMessage('Bundled typescript module not found', 'error')
return null return null
} }
} }

View file

@ -1,4 +1,4 @@
import { Uri, StatusBarItem, workspace, events } from 'coc.nvim' import { events, StatusBarItem, Uri, window, workspace } from 'coc.nvim'
import { Disposable } from 'vscode-languageserver-protocol' import { Disposable } from 'vscode-languageserver-protocol'
import { TypeScriptVersion } from './versionProvider' import { TypeScriptVersion } from './versionProvider'
@ -10,7 +10,7 @@ export default class VersionStatus {
private readonly _normalizePath: (resource: Uri) => string | null, private readonly _normalizePath: (resource: Uri) => string | null,
private readonly enableJavascript: boolean private readonly enableJavascript: boolean
) { ) {
this._versionBarEntry = workspace.createStatusBarItem(99) this._versionBarEntry = window.createStatusBarItem(99)
this._onChangeEditorSub = events.on('BufEnter', this.onBufEnter, this) this._onChangeEditorSub = events.on('BufEnter', this.onBufEnter, this)
this._versionBarEntry.show() this._versionBarEntry.show()
} }

3167
yarn.lock

File diff suppressed because it is too large Load diff