mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-22 01:29:04 +01:00
Move language configurations registration to manager
This commit is contained in:
@@ -4,21 +4,19 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
import { CommandManager } from './utils/commandManager';
|
||||
import TypeScriptServiceClientHost from './typeScriptServiceClientHost';
|
||||
import * as commands from './commands';
|
||||
|
||||
import { LanguageConfigurationManager } from './features/languageConfiguration';
|
||||
import TypeScriptTaskProviderManager from './features/taskProvider';
|
||||
import TypeScriptServiceClientHost from './typeScriptServiceClientHost';
|
||||
import { CommandManager } from './utils/commandManager';
|
||||
import * as fileSchemes from './utils/fileSchemes';
|
||||
import { standardLanguageDescriptions } from './utils/languageDescription';
|
||||
import { lazy, Lazy } from './utils/lazy';
|
||||
import LogDirectoryProvider from './utils/logDirectoryProvider';
|
||||
import ManagedFileContextManager from './utils/managedFileContext';
|
||||
import { getContributedTypeScriptServerPlugins, TypeScriptServerPlugin } from './utils/plugins';
|
||||
import * as ProjectStatus from './utils/projectStatus';
|
||||
import * as languageModeIds from './utils/languageModeIds';
|
||||
import * as languageConfigurations from './utils/languageConfigurations';
|
||||
import { standardLanguageDescriptions } from './utils/languageDescription';
|
||||
import ManagedFileContextManager from './utils/managedFileContext';
|
||||
import { lazy, Lazy } from './utils/lazy';
|
||||
import * as fileSchemes from './utils/fileSchemes';
|
||||
import LogDirectoryProvider from './utils/logDirectoryProvider';
|
||||
|
||||
|
||||
export function activate(
|
||||
context: vscode.ExtensionContext
|
||||
@@ -32,7 +30,7 @@ export function activate(
|
||||
|
||||
registerCommands(commandManager, lazyClientHost);
|
||||
context.subscriptions.push(new TypeScriptTaskProviderManager(lazyClientHost.map(x => x.serviceClient)));
|
||||
context.subscriptions.push(vscode.languages.setLanguageConfiguration(languageModeIds.jsxTags, languageConfigurations.jsxTags));
|
||||
context.subscriptions.push(new LanguageConfigurationManager());
|
||||
|
||||
const supportedLanguage = [].concat.apply([], standardLanguageDescriptions.map(x => x.modeIds).concat(plugins.map(x => x.languages)));
|
||||
function didOpenTextDocument(textDocument: vscode.TextDocument): boolean {
|
||||
|
||||
@@ -8,9 +8,11 @@
|
||||
* https://github.com/Microsoft/TypeScript-Sublime-Plugin/blob/master/TypeScript%20Indent.tmPreferences
|
||||
* ------------------------------------------------------------------------------------------ */
|
||||
|
||||
import { IndentAction } from 'vscode';
|
||||
import * as vscode from 'vscode';
|
||||
import { disposeAll } from '../utils/dispose';
|
||||
import * as languageModeIds from '../utils/languageModeIds';
|
||||
|
||||
export const jsTsLanguageConfiguration = {
|
||||
const jsTsLanguageConfiguration: vscode.LanguageConfiguration = {
|
||||
indentationRules: {
|
||||
// ^(.*\*/)?\s*\}.*$
|
||||
decreaseIndentPattern: /^((?!.*?\/\*).*\*\/)?\s*[\}\]\)].*$/,
|
||||
@@ -23,41 +25,67 @@ export const jsTsLanguageConfiguration = {
|
||||
// e.g. /** | */
|
||||
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
|
||||
afterText: /^\s*\*\/$/,
|
||||
action: { indentAction: IndentAction.IndentOutdent, appendText: ' * ' }
|
||||
action: { indentAction: vscode.IndentAction.IndentOutdent, appendText: ' * ' }
|
||||
}, {
|
||||
// e.g. /** ...|
|
||||
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
|
||||
action: { indentAction: IndentAction.None, appendText: ' * ' }
|
||||
action: { indentAction: vscode.IndentAction.None, appendText: ' * ' }
|
||||
}, {
|
||||
// e.g. * ...|
|
||||
beforeText: /^(\t|[ ])*[ ]\*([ ]([^\*]|\*(?!\/))*)?$/,
|
||||
action: { indentAction: IndentAction.None, appendText: '* ' }
|
||||
action: { indentAction: vscode.IndentAction.None, appendText: '* ' }
|
||||
}, {
|
||||
// e.g. */|
|
||||
beforeText: /^(\t|[ ])*[ ]\*\/\s*$/,
|
||||
action: { indentAction: IndentAction.None, removeText: 1 }
|
||||
action: { indentAction: vscode.IndentAction.None, removeText: 1 }
|
||||
},
|
||||
{
|
||||
// e.g. *-----*/|
|
||||
beforeText: /^(\t|[ ])*[ ]\*[^/]*\*\/\s*$/,
|
||||
action: { indentAction: IndentAction.None, removeText: 1 }
|
||||
action: { indentAction: vscode.IndentAction.None, removeText: 1 }
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
const EMPTY_ELEMENTS: string[] = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr'];
|
||||
|
||||
export const jsxTags = {
|
||||
const jsxTagsLanguageConfiguration: vscode.LanguageConfiguration = {
|
||||
wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\$\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\s]+)/g,
|
||||
onEnterRules: [
|
||||
{
|
||||
beforeText: new RegExp(`<(?!(?:${EMPTY_ELEMENTS.join('|')}))([_:\\w][_:\\w-.\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'),
|
||||
afterText: /^<\/([_:\w][_:\w-.\d]*)\s*>$/i,
|
||||
action: { indentAction: IndentAction.IndentOutdent }
|
||||
action: { indentAction: vscode.IndentAction.IndentOutdent }
|
||||
},
|
||||
{
|
||||
beforeText: new RegExp(`<(?!(?:${EMPTY_ELEMENTS.join('|')}))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'),
|
||||
action: { indentAction: IndentAction.Indent }
|
||||
action: { indentAction: vscode.IndentAction.Indent }
|
||||
}
|
||||
],
|
||||
};
|
||||
};
|
||||
|
||||
export class LanguageConfigurationManager {
|
||||
private readonly _registrations: vscode.Disposable[] = [];
|
||||
|
||||
constructor() {
|
||||
const standardLanguages = [
|
||||
languageModeIds.javascript,
|
||||
languageModeIds.javascriptreact,
|
||||
languageModeIds.typescript,
|
||||
languageModeIds.typescriptreact,
|
||||
];
|
||||
for (const language of standardLanguages) {
|
||||
this.registerConfiguration(language, jsTsLanguageConfiguration);
|
||||
}
|
||||
|
||||
this.registerConfiguration(languageModeIds.jsxTags, jsxTagsLanguageConfiguration);
|
||||
}
|
||||
|
||||
private registerConfiguration(language: string, config: vscode.LanguageConfiguration) {
|
||||
this._registrations.push(vscode.languages.setLanguageConfiguration(language, config));
|
||||
}
|
||||
|
||||
dispose() {
|
||||
disposeAll(this._registrations);
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,6 @@ import BufferSyncSupport from './features/bufferSyncSupport';
|
||||
|
||||
import TypingsStatus from './utils/typingsStatus';
|
||||
import FileConfigurationManager from './features/fileConfigurationManager';
|
||||
import * as languageConfigurations from './utils/languageConfigurations';
|
||||
import { CommandManager } from './utils/commandManager';
|
||||
import { DiagnosticsManager, DiagnosticKind } from './features/diagnostics';
|
||||
import { LanguageDescription } from './utils/languageDescription';
|
||||
@@ -162,12 +161,6 @@ export default class LanguageProvider {
|
||||
this.disposables.push(languages.registerCodeLensProvider(selector, implementationCodeLensProvider));
|
||||
|
||||
this.disposables.push(languages.registerWorkspaceSymbolProvider(new (await import('./features/workspaceSymbolProvider')).default(client, this.description.modeIds)));
|
||||
|
||||
if (!this.description.isExternal) {
|
||||
for (const modeId of this.description.modeIds) {
|
||||
this.disposables.push(languages.setLanguageConfiguration(modeId, languageConfigurations.jsTsLanguageConfiguration));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async initFoldingProvider(): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user