mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
typescript.experimental.syntaxFolding (#44444)
This commit is contained in:
parent
8eddfa2cfb
commit
44a45f8bad
|
@ -395,6 +395,11 @@
|
|||
"default": null,
|
||||
"description": "%typescript.locale%",
|
||||
"scope": "window"
|
||||
},
|
||||
"typescript.experimental.syntaxFolding": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "%typescript.experimental.syntaxFolding%"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -454,7 +459,8 @@
|
|||
"value": "%typescript.restartTsServer%"
|
||||
},
|
||||
"category": "TypeScript"
|
||||
}
|
||||
},
|
||||
|
||||
],
|
||||
"menus": {
|
||||
"commandPalette": [
|
||||
|
|
|
@ -48,5 +48,6 @@
|
|||
"typescript.quickSuggestionsForPaths": "Enable/disable quick suggestions when typing out an import path.",
|
||||
"typescript.locale": "Sets the locale used to report TypeScript errors. Requires TypeScript >= 2.6.0. Default of 'null' uses VS Code's locale for TypeScript errors.",
|
||||
"javascript.implicitProjectConfig.experimentalDecorators": "Enable/disable 'experimentalDecorators' for JavaScript files that are not part of a project. Existing jsconfig.json or tsconfig.json files override this setting. Requires TypeScript >=2.3.1.",
|
||||
"typescript.autoImportSuggestions.enabled": "Enable/disable auto import suggestions. Requires TypeScript >=2.6.1"
|
||||
"typescript.autoImportSuggestions.enabled": "Enable/disable auto import suggestions. Requires TypeScript >=2.6.1",
|
||||
"typescript.experimental.syntaxFolding": "Enables/disables syntax aware folding markers.",
|
||||
}
|
|
@ -20,6 +20,7 @@ import * as fileSchemes from './utils/fileSchemes';
|
|||
import { CachedNavTreeResponse } from './features/baseCodeLensProvider';
|
||||
|
||||
const validateSetting = 'validate.enable';
|
||||
const foldingSetting = 'typescript.experimental.syntaxFolding';
|
||||
|
||||
export default class LanguageProvider {
|
||||
private readonly diagnosticsManager: DiagnosticsManager;
|
||||
|
@ -35,6 +36,8 @@ export default class LanguageProvider {
|
|||
private readonly disposables: Disposable[] = [];
|
||||
private readonly versionDependentDisposables: Disposable[] = [];
|
||||
|
||||
private foldingProviderRegistration: Disposable | undefined = void 0;
|
||||
|
||||
constructor(
|
||||
private readonly client: TypeScriptServiceClient,
|
||||
private readonly description: LanguageDescription,
|
||||
|
@ -126,9 +129,13 @@ export default class LanguageProvider {
|
|||
this.disposables.push(languages.registerCodeActionsProvider(selector, new (await import('./features/quickFixProvider')).default(client, this.formattingOptionsManager, commandManager, this.diagnosticsManager)));
|
||||
this.disposables.push(languages.registerCodeActionsProvider(selector, new (await import('./features/refactorProvider')).default(client, this.formattingOptionsManager, commandManager)));
|
||||
|
||||
if (workspace.getConfiguration('typescript').get('enableExperimentalFolding', false)) {
|
||||
this.disposables.push(languages.registerFoldingProvider(selector, new (await import('./features/folderingProvider')).default(client)));
|
||||
}
|
||||
await this.initFoldingProvider();
|
||||
this.disposables.push(workspace.onDidChangeConfiguration(c => {
|
||||
if (c.affectsConfiguration(foldingSetting)) {
|
||||
this.initFoldingProvider();
|
||||
}
|
||||
}));
|
||||
this.disposables.push({ dispose: () => this.foldingProviderRegistration && this.foldingProviderRegistration.dispose() });
|
||||
|
||||
this.registerVersionDependentProviders();
|
||||
|
||||
|
@ -153,6 +160,20 @@ export default class LanguageProvider {
|
|||
}
|
||||
}
|
||||
|
||||
private async initFoldingProvider(): Promise<void> {
|
||||
let enable = workspace.getConfiguration().get(foldingSetting, false);
|
||||
if (enable) {
|
||||
if (!this.foldingProviderRegistration) {
|
||||
this.foldingProviderRegistration = languages.registerFoldingProvider(this.documentSelector, new (await import('./features/folderingProvider')).default(this.client));
|
||||
}
|
||||
} else {
|
||||
if (this.foldingProviderRegistration) {
|
||||
this.foldingProviderRegistration.dispose();
|
||||
this.foldingProviderRegistration = void 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private configurationChanged(): void {
|
||||
const config = workspace.getConfiguration(this.id);
|
||||
this.updateValidate(config.get(validateSetting, true));
|
||||
|
|
Loading…
Reference in a new issue