diff --git a/extensions/vscode-colorize-tests/src/colorizer.test.ts b/extensions/vscode-colorize-tests/src/colorizer.test.ts index 815f548fee3..07f4dd33de6 100644 --- a/extensions/vscode-colorize-tests/src/colorizer.test.ts +++ b/extensions/vscode-colorize-tests/src/colorizer.test.ts @@ -65,14 +65,19 @@ suite('colorization', () => { const fixturesPath = join(testPath, 'colorize-fixtures'); const resultsPath = join(testPath, 'colorize-results'); const treeSitterResultsPath = join(testPath, 'colorize-tree-sitter-results'); - let originalSettingValue: any; + let originalSettingValues: any[]; suiteSetup(async function () { - originalSettingValue = workspace.getConfiguration('editor').get('experimental.preferTreeSitter'); - await workspace.getConfiguration('editor').update('experimental.preferTreeSitter', ["typescript", "ini"], ConfigurationTarget.Global); + originalSettingValues = [ + workspace.getConfiguration('editor.experimental').get('preferTreeSitter.typescript'), + workspace.getConfiguration('editor.experimental').get('preferTreeSitter.ini') + ]; + await workspace.getConfiguration('editor.experimental').update('preferTreeSitter.typescript', true, ConfigurationTarget.Global); + await workspace.getConfiguration('editor.experimental').update('preferTreeSitter.ini', true, ConfigurationTarget.Global); }); suiteTeardown(async function () { - await workspace.getConfiguration('editor').update('experimental.preferTreeSitter', originalSettingValue, ConfigurationTarget.Global); + await workspace.getConfiguration('editor.experimental').update('preferTreeSitter.typescript', originalSettingValues[0], ConfigurationTarget.Global); + await workspace.getConfiguration('editor.experimental').update('preferTreeSitter.ini', originalSettingValues[1], ConfigurationTarget.Global); }); for (const fixture of fs.readdirSync(fixturesPath)) { diff --git a/src/vs/editor/common/config/editorConfigurationSchema.ts b/src/vs/editor/common/config/editorConfigurationSchema.ts index cae3fb2bb94..03f29bef928 100644 --- a/src/vs/editor/common/config/editorConfigurationSchema.ts +++ b/src/vs/editor/common/config/editorConfigurationSchema.ts @@ -115,14 +115,16 @@ const editorConfiguration: IConfigurationNode = { markdownDescription: nls.localize('editor.experimental.treeSitterTelemetry', "Controls whether tree sitter parsing should be turned on and telemetry collected. Setting `editor.experimental.preferTreeSitter` for specific languages will take precedence."), tags: ['experimental', 'onExP'] }, - 'editor.experimental.preferTreeSitter': { - type: 'array', - items: { - type: 'string', - enum: ['typescript', 'ini'] - }, - default: ['ini'], - markdownDescription: nls.localize('editor.experimental.preferTreeSitter', "Controls whether tree sitter parsing should be turned on for specific languages. This will take precedence over `editor.experimental.treeSitterTelemetry` for the specified languages."), + 'editor.experimental.preferTreeSitter.typescript': { + type: 'boolean', + default: false, + markdownDescription: nls.localize('editor.experimental.preferTreeSitter.typescript', "Controls whether tree sitter parsing should be turned on for typescript. This will take precedence over `editor.experimental.treeSitterTelemetry` for typescript."), + tags: ['experimental'] + }, + 'editor.experimental.preferTreeSitter.ini': { + type: 'boolean', + default: false, + markdownDescription: nls.localize('editor.experimental.preferTreeSitter.ini', "Controls whether tree sitter parsing should be turned on for ini. This will take precedence over `editor.experimental.treeSitterTelemetry` for ini."), tags: ['experimental'] }, 'editor.language.brackets': { diff --git a/src/vs/editor/common/services/treeSitter/treeSitterParserService.ts b/src/vs/editor/common/services/treeSitter/treeSitterParserService.ts index c54327aa420..979191c6871 100644 --- a/src/vs/editor/common/services/treeSitter/treeSitterParserService.ts +++ b/src/vs/editor/common/services/treeSitter/treeSitterParserService.ts @@ -5,7 +5,7 @@ import type * as Parser from '@vscode/tree-sitter-wasm'; import { AppResourcePath, FileAccess, nodeModulesAsarUnpackedPath, nodeModulesPath } from '../../../../base/common/network.js'; -import { EDITOR_EXPERIMENTAL_PREFER_TREESITTER, ITreeSitterParserService, ITreeSitterParseResult, ITextModelTreeSitter, RangeChange, TreeUpdateEvent, TreeParseUpdateEvent, ITreeSitterImporter } from '../treeSitterParserService.js'; +import { EDITOR_EXPERIMENTAL_PREFER_TREESITTER, ITreeSitterParserService, ITreeSitterParseResult, ITextModelTreeSitter, RangeChange, TreeUpdateEvent, TreeParseUpdateEvent, ITreeSitterImporter, TREESITTER_ALLOWED_SUPPORT } from '../treeSitterParserService.js'; import { IModelService } from '../model.js'; import { Disposable, DisposableMap, DisposableStore, dispose, IDisposable } from '../../../../base/common/lifecycle.js'; import { ITextModel } from '../../model.js'; @@ -654,15 +654,11 @@ export class TreeSitterTextModelService extends Disposable implements ITreeSitte } private async _supportedLanguagesChanged() { - const setting = this._getSetting(); - - let hasLanguages = true; - if (setting.length === 0) { - hasLanguages = false; - } + let hasLanguages = false; const handleLanguage = (languageId: string) => { - if (setting.includes(languageId)) { + if (this._getSetting(languageId)) { + hasLanguages = true; this._addGrammar(languageId, `tree-sitter-${languageId}`); } else { this._removeGrammar(languageId); @@ -670,23 +666,19 @@ export class TreeSitterTextModelService extends Disposable implements ITreeSitte }; // Eventually, this should actually use an extension point to add tree sitter grammars, but for now they are hard coded in core - handleLanguage('typescript'); - handleLanguage('ini'); + for (const languageId of TREESITTER_ALLOWED_SUPPORT) { + handleLanguage(languageId); + } return this._initParser(hasLanguages); } - private _getSetting(): string[] { - const setting = this._configurationService.getValue(EDITOR_EXPERIMENTAL_PREFER_TREESITTER); - if (setting && setting.length > 0) { - return setting; - } else { - const expSetting = this._configurationService.getValue(EDITOR_TREESITTER_TELEMETRY); - if (expSetting) { - return ['typescript']; - } + private _getSetting(languageId: string): boolean { + const setting = this._configurationService.getValue(`${EDITOR_EXPERIMENTAL_PREFER_TREESITTER}.${languageId}`); + if (!setting && TREESITTER_ALLOWED_SUPPORT.includes(languageId)) { + return this._configurationService.getValue(EDITOR_TREESITTER_TELEMETRY); } - return []; + return setting; } private async _registerModelServiceListeners() { diff --git a/src/vs/editor/common/services/treeSitterParserService.ts b/src/vs/editor/common/services/treeSitterParserService.ts index 9a690754a52..6e157eae8ad 100644 --- a/src/vs/editor/common/services/treeSitterParserService.ts +++ b/src/vs/editor/common/services/treeSitterParserService.ts @@ -11,6 +11,7 @@ import { Range } from '../core/range.js'; import { importAMDNodeModule } from '../../../amdX.js'; export const EDITOR_EXPERIMENTAL_PREFER_TREESITTER = 'editor.experimental.preferTreeSitter'; +export const TREESITTER_ALLOWED_SUPPORT = ['typescript', 'ini']; export const ITreeSitterParserService = createDecorator('treeSitterParserService'); diff --git a/src/vs/workbench/services/treeSitter/browser/treeSitterTokenizationFeature.ts b/src/vs/workbench/services/treeSitter/browser/treeSitterTokenizationFeature.ts index 6ed4ed3223a..df63189aa27 100644 --- a/src/vs/workbench/services/treeSitter/browser/treeSitterTokenizationFeature.ts +++ b/src/vs/workbench/services/treeSitter/browser/treeSitterTokenizationFeature.ts @@ -9,7 +9,7 @@ import { Disposable, DisposableMap, DisposableStore, IDisposable } from '../../. import { AppResourcePath, FileAccess } from '../../../../base/common/network.js'; import { ILanguageIdCodec, ITreeSitterTokenizationSupport, LazyTokenizationSupport, QueryCapture, TreeSitterTokenizationRegistry } from '../../../../editor/common/languages.js'; import { ITextModel } from '../../../../editor/common/model.js'; -import { EDITOR_EXPERIMENTAL_PREFER_TREESITTER, ITreeSitterParserService, ITreeSitterParseResult, TreeUpdateEvent, RangeChange, ITreeSitterImporter } from '../../../../editor/common/services/treeSitterParserService.js'; +import { EDITOR_EXPERIMENTAL_PREFER_TREESITTER, ITreeSitterParserService, ITreeSitterParseResult, TreeUpdateEvent, RangeChange, ITreeSitterImporter, TREESITTER_ALLOWED_SUPPORT } from '../../../../editor/common/services/treeSitterParserService.js'; import { IModelTokensChangedEvent } from '../../../../editor/common/textModelEvents.js'; import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js'; import { IFileService } from '../../../../platform/files/common/files.js'; @@ -28,7 +28,6 @@ import { setTimeout0 } from '../../../../base/common/platform.js'; import { findLikelyRelevantLines } from '../../../../editor/common/model/textModelTokens.js'; import { TreeSitterCodeEditors } from './treeSitterCodeEditors.js'; -const ALLOWED_SUPPORT = ['typescript', 'ini']; type TreeSitterQueries = string; export const ITreeSitterTokenizationFeature = createDecorator('treeSitterTokenizationFeature'); @@ -63,16 +62,15 @@ export class TreeSitterTokenizationFeature extends Disposable implements ITreeSi })); } - private _getSetting(): string[] { - return this._configurationService.getValue(EDITOR_EXPERIMENTAL_PREFER_TREESITTER) || []; + private _getSetting(languageId: string): boolean { + return this._configurationService.getValue(`${EDITOR_EXPERIMENTAL_PREFER_TREESITTER}.${languageId}`); } private _handleGrammarsExtPoint(): void { - const setting = this._getSetting(); - // Eventually, this should actually use an extension point to add tree sitter grammars, but for now they are hard coded in core - for (const languageId of setting) { - if (ALLOWED_SUPPORT.includes(languageId) && !this._tokenizersRegistrations.has(languageId)) { + for (const languageId of TREESITTER_ALLOWED_SUPPORT) { + const setting = this._getSetting(languageId); + if (setting && !this._tokenizersRegistrations.has(languageId)) { const lazyTokenizationSupport = new LazyTokenizationSupport(() => this._createTokenizationSupport(languageId)); const disposableStore = new DisposableStore(); disposableStore.add(lazyTokenizationSupport); @@ -81,7 +79,7 @@ export class TreeSitterTokenizationFeature extends Disposable implements ITreeSi TreeSitterTokenizationRegistry.getOrCreate(languageId); } } - const languagesToUnregister = [...this._tokenizersRegistrations.keys()].filter(languageId => !setting.includes(languageId)); + const languagesToUnregister = [...this._tokenizersRegistrations.keys()].filter(languageId => !this._getSetting(languageId)); for (const languageId of languagesToUnregister) { this._tokenizersRegistrations.deleteAndDispose(languageId); } diff --git a/src/vs/workbench/test/electron-main/treeSitterTokenizationFeature.test.ts b/src/vs/workbench/test/electron-main/treeSitterTokenizationFeature.test.ts index 051834632ad..4913ea55de5 100644 --- a/src/vs/workbench/test/electron-main/treeSitterTokenizationFeature.test.ts +++ b/src/vs/workbench/test/electron-main/treeSitterTokenizationFeature.test.ts @@ -116,7 +116,7 @@ suite('Tree Sitter TokenizationFeature', function () { let languageConfigurationService: ILanguageConfigurationService; const telemetryService: ITelemetryService = new MockTelemetryService(); const logService: ILogService = new NullLogService(); - const configurationService: IConfigurationService = new TestConfigurationService({ 'editor.experimental.preferTreeSitter': ['typescript'] }); + const configurationService: IConfigurationService = new TestConfigurationService({ 'editor.experimental.preferTreeSitter.typescript': true }); const themeService: IThemeService = new TestThemeService(new TestTreeSitterColorTheme()); let languageService: ILanguageService; const environmentService: IEnvironmentService = {} as IEnvironmentService;