check languageId for current document

This commit is contained in:
chemzqm 2018-11-07 19:54:23 +08:00
parent bb2bd8f5cd
commit 786cdcd252
3 changed files with 8 additions and 20 deletions

View file

@ -45,6 +45,11 @@
"category": "TSServer",
"command": "tsserver.goToProjectConfig"
},
{
"title": "Restart tsserver",
"category": "TSServer",
"command": "tsserver.restart"
},
{
"title": "Run `tsc --watch` for current project in terminal buffer.",
"category": "TSServer",

View file

@ -2,12 +2,11 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { commands, workspace } from 'coc.nvim'
import { workspace } from 'coc.nvim'
import { DocumentFormattingEditProvider, DocumentRangeFormattingEditProvider } from 'coc.nvim/lib/provider'
import { CancellationToken, FormattingOptions, Position, Range, TextDocument, TextEdit } from 'vscode-languageserver-protocol'
import * as Proto from '../protocol'
import { ITypeScriptServiceClient } from '../typescriptService'
import { languageIds } from '../utils/languageModeIds'
import { removeSemicolon } from '../utils/semicolon'
import * as typeConverters from '../utils/typeConverters'
import FileConfigurationManager from './fileConfigurationManager'
@ -20,23 +19,6 @@ export default class TypeScriptFormattingProvider
private readonly client: ITypeScriptServiceClient,
private readonly formattingOptionsManager: FileConfigurationManager
) {
commands.register({
id: 'tsserver.format',
execute: async (): Promise<void> => {
let document = await workspace.document
if (!document) return
if (languageIds.indexOf(document.filetype) == -1) {
return
}
let options = await workspace.getFormatOptions()
let edit = await this.provideDocumentFormattingEdits(
document.textDocument,
options
)
if (!edit) return
await document.applyEdits(workspace.nvim, edit)
}
})
}
private async doFormat(

View file

@ -18,6 +18,7 @@ import API from './utils/api'
import { TsServerLogLevel, TypeScriptServiceConfiguration } from './utils/configuration'
import Logger from './utils/logger'
import { fork, getTempFile, IForkOptions, makeRandomHexString } from './utils/process'
import { languageIds } from './utils/languageModeIds'
import Tracer from './utils/tracer'
import { inferredProjectConfig } from './utils/tsconfig'
import { TypeScriptVersion, TypeScriptVersionProvider } from './utils/versionProvider'
@ -422,7 +423,7 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
private serviceStarted(resendModels: boolean): void {
let document = workspace.getDocument(workspace.bufnr)
if (document) {
if (document && languageIds.indexOf(document.filetype) !== -1) {
this.fileConfigurationManager.ensureConfigurationForDocument(document.textDocument) // tslint:disable-line
} else {
const configureOptions: Proto.ConfigureRequestArguments = {