|
| 1 | +import * as path from 'path'; |
1 | 2 | import { |
2 | | - workspace, |
| 3 | + commands, |
3 | 4 | ExtensionContext, |
4 | | - TextDocument, |
| 5 | + extensions, |
| 6 | + IndentAction, |
| 7 | + languages, |
5 | 8 | Position, |
| 9 | + ProgressLocation, |
6 | 10 | Range, |
7 | | - commands, |
8 | | - window, |
9 | | - WorkspaceEdit, |
| 11 | + TextDocument, |
10 | 12 | Uri, |
11 | | - ProgressLocation, |
12 | 13 | ViewColumn, |
13 | | - languages, |
14 | | - IndentAction, |
15 | | - extensions |
| 14 | + window, |
| 15 | + workspace, |
| 16 | + WorkspaceEdit |
16 | 17 | } from 'vscode'; |
17 | 18 | import { |
| 19 | + ExecuteCommandRequest, |
18 | 20 | LanguageClientOptions, |
19 | | - TextDocumentPositionParams, |
20 | 21 | RequestType, |
21 | 22 | RevealOutputChannelOn, |
22 | | - WorkspaceEdit as LSWorkspaceEdit, |
23 | 23 | TextDocumentEdit, |
24 | | - ExecuteCommandRequest |
| 24 | + TextDocumentPositionParams, |
| 25 | + WorkspaceEdit as LSWorkspaceEdit |
25 | 26 | } from 'vscode-languageclient'; |
26 | 27 | import { LanguageClient, ServerOptions, TransportKind } from 'vscode-languageclient/node'; |
| 28 | +import CompiledCodeContentProvider from './CompiledCodeContentProvider'; |
27 | 29 | import { activateTagClosing } from './html/autoClose'; |
28 | 30 | import { EMPTY_ELEMENTS } from './html/htmlEmptyTagsShared'; |
29 | | -import CompiledCodeContentProvider from './CompiledCodeContentProvider'; |
30 | | -import * as path from 'path'; |
31 | | -import { readFileSync, writeFileSync } from 'fs'; |
| 31 | +import { TsPlugin } from './tsplugin'; |
32 | 32 |
|
33 | 33 | namespace TagCloseRequest { |
34 | 34 | export const type: RequestType<TextDocumentPositionParams, string, any> = new RequestType( |
@@ -173,7 +173,7 @@ export function activate(context: ExtensionContext) { |
173 | 173 |
|
174 | 174 | addExtracComponentCommand(getLS, context); |
175 | 175 |
|
176 | | - context.subscriptions.push(commands.registerCommand('svelte.toggleTsPlugin', toggleTsPlugin)); |
| 176 | + TsPlugin.create(context); |
177 | 177 |
|
178 | 178 | languages.setLanguageConfiguration('svelte', { |
179 | 179 | indentationRules: { |
@@ -387,46 +387,6 @@ function addExtracComponentCommand(getLS: () => LanguageClient, context: Extensi |
387 | 387 | ); |
388 | 388 | } |
389 | 389 |
|
390 | | -function toggleTsPlugin() { |
391 | | - const extension = extensions.getExtension('svelte.svelte-vscode'); |
392 | | - if (!extension) { |
393 | | - // This shouldn't be possible |
394 | | - return; |
395 | | - } |
396 | | - |
397 | | - const packageJson = path.join(extension.extensionPath, 'package.json'); |
398 | | - const enabled = '"typescriptServerPlugins"'; |
399 | | - const disabled = '"typescriptServerPlugins-disabled"'; |
400 | | - try { |
401 | | - const packageText = readFileSync(packageJson, 'utf8'); |
402 | | - if (packageText.includes(disabled)) { |
403 | | - const newText = packageText.replace(disabled, enabled); |
404 | | - writeFileSync(packageJson, newText, 'utf8'); |
405 | | - showReload(true); |
406 | | - } else if (packageText.includes(enabled)) { |
407 | | - const newText = packageText.replace(enabled, disabled); |
408 | | - writeFileSync(packageJson, newText, 'utf8'); |
409 | | - showReload(false); |
410 | | - } else { |
411 | | - window.showWarningMessage('Unknown Svelte for VS Code package.json status.'); |
412 | | - } |
413 | | - } catch (err) { |
414 | | - window.showWarningMessage('Svelte for VS Code package.json update failed.'); |
415 | | - } |
416 | | - |
417 | | - async function showReload(enabled: boolean) { |
418 | | - const reload = await window.showInformationMessage( |
419 | | - ` TypeScript Svelte Plugin ${ |
420 | | - enabled ? 'enabled' : 'disabled' |
421 | | - }, please reload VS Code to restart the TS Server.`, |
422 | | - 'Reload Window' |
423 | | - ); |
424 | | - if (reload) { |
425 | | - commands.executeCommand('workbench.action.reloadWindow'); |
426 | | - } |
427 | | - } |
428 | | -} |
429 | | - |
430 | 390 | function createLanguageServer(serverOptions: ServerOptions, clientOptions: LanguageClientOptions) { |
431 | 391 | return new LanguageClient('svelte', 'Svelte', serverOptions, clientOptions); |
432 | 392 | } |
|
0 commit comments