Skip to content

Commit

Permalink
Add config option to disable the language server
Browse files Browse the repository at this point in the history
  • Loading branch information
wolmir committed Oct 3, 2022
1 parent 51bd789 commit acdb4fe
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
6 changes: 6 additions & 0 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,12 @@
"type": "boolean",
"default": null
},
"dvc.disableLanguageServer": {
"title": "%config.disableLanguageServer.title%",
"description": "%config.disableLanguageServer.description%",
"type": "boolean",
"default": null
},
"dvc.dvcPath": {
"title": "%config.dvcPath.title%",
"description": "%config.dvcPath.description%",
Expand Down
2 changes: 2 additions & 0 deletions extension/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
"config.doNotShowWalkthroughAfterInstall.title": "Do not show the Get Started page.",
"config.doNotShowUnableToFilter.description": "Do not warn before disabling auto-apply filters when these would result in too many experiments being selected.",
"config.doNotShowUnableToFilter.title": "Do not warn before disabling auto-apply filters to experiment selection.",
"config.disableLanguageServer.description": "Disable the language server for dvc.yaml files.",
"config.disableLanguageServer.title": "Disable language server",
"config.dvcPath.description": "Path or shell command to the DVC binary. Required unless Microsoft's Python extension is installed and the `dvc` package found in its environment.",
"config.dvcPath.title": "DVC Path (or shell command)",
"config.expTableHeadMaxLayers.title": "Maximum depth of Experiment table head rows",
Expand Down
3 changes: 3 additions & 0 deletions extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { collectWorkspaceScale } from './telemetry/collect'
import { createFileSystemWatcher } from './fileSystem/watcher'
import { GitExecutor } from './cli/git/executor'
import { GitReader } from './cli/git/reader'
import { LanguageClientWrapper } from './lspClient/languageClient'

export class Extension extends Disposable implements IExtension {
protected readonly internalCommands: InternalCommands
Expand Down Expand Up @@ -92,6 +93,8 @@ export class Extension extends Disposable implements IExtension {
this.setCommandsAvailability(false)
this.setProjectAvailability()

this.dispose.track(new LanguageClientWrapper())

this.resourceLocator = this.dispose.track(
new ResourceLocator(context.extensionUri)
)
Expand Down
26 changes: 24 additions & 2 deletions extension/src/lspClient/languageClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import {
TransportKind
} from 'vscode-languageclient/node'
import { documentSelector, serverModule } from 'dvc-vscode-lsp'
import { ConfigurationChangeEvent, workspace } from 'vscode'
import { Disposable } from '../class/dispose'
import { ConfigKey, getConfigValue } from '../vscode/config'

export class LanguageClientWrapper extends Disposable {
private client: LanguageClient
Expand All @@ -26,12 +28,24 @@ export class LanguageClientWrapper extends Disposable {
)
)

// Start the client. This will also launch the server
this.start()
}

async start() {
await this.client.start()
if (!this.languageServerDisabled()) {
// This will also start the server process
await this.client.start()

workspace.onDidChangeConfiguration((event: ConfigurationChangeEvent) => {
if (
event.affectsConfiguration(ConfigKey.DISABLE_LANGUAGE_SERVER) &&
this.isRunning() &&
this.languageServerDisabled()
) {
this.stop()
}
})
}

return this
}
Expand All @@ -40,6 +54,14 @@ export class LanguageClientWrapper extends Disposable {
this.client.stop()
}

private isRunning() {
return this.client.isRunning()
}

private languageServerDisabled() {
return getConfigValue<boolean>(ConfigKey.DISABLE_LANGUAGE_SERVER)
}

private getServerOptions(): ServerOptions {
const debugOptions = { execArgv: ['--nolazy', '--inspect=6009'] }

Expand Down
1 change: 1 addition & 0 deletions extension/src/vscode/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum ConfigKey {
DO_NOT_SHOW_CLI_UNAVAILABLE = 'dvc.doNotShowCliUnavailable',
DO_NOT_SHOW_WALKTHROUGH_AFTER_INSTALL = 'dvc.doNotShowWalkthroughAfterInstall',
DO_NOT_SHOW_UNABLE_TO_FILTER = 'dvc.doNotShowUnableToFilter',
DISABLE_LANGUAGE_SERVER = 'dvc.disableLanguageServer',
EXP_TABLE_HEAD_MAX_LAYERS = 'dvc.expTableHeadMaxLayers',
DVC_PATH = 'dvc.dvcPath',
PYTHON_PATH = 'dvc.pythonPath'
Expand Down

0 comments on commit acdb4fe

Please sign in to comment.