mirror of
https://github.com/microsoft/vscode.git
synced 2026-08-19 22:42:35 +01:00
Fixes #1533: Code formatting settings
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
"vscode-nls": "^1.0.4"
|
||||
},
|
||||
"scripts": {
|
||||
"vscode:prepublish": "node ../../node_modules/gulp/bin/gulp.js --gulpfile ../../build/gulpfile.extensions.js compile-extension:typescript ./src/tsconfig.json"
|
||||
"vscode:prepublish": "node ../../node_modules/gulp/bin/gulp.js --gulpfile ../../build/gulpfile.extensions.js compile-extension:typescript ./tsconfig.json"
|
||||
},
|
||||
"activationEvents": [
|
||||
"onLanguage:javascript",
|
||||
@@ -66,25 +66,115 @@
|
||||
"type": "object",
|
||||
"title": "%configuration.typescript%",
|
||||
"properties": {
|
||||
"typescript.useCodeSnippetsOnMethodSuggest": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "%typescript.useCodeSnippetsOnMethodSuggest.dec%"
|
||||
},
|
||||
"typescript.tsdk": {
|
||||
"type": ["string", "null"],
|
||||
"default": null,
|
||||
"description": "%typescript.tsdk.desc%"
|
||||
},
|
||||
"typescript.useCodeSnippetsOnMethodSuggest": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "%typescript.useCodeSnippetsOnMethodSuggest.dec%"
|
||||
},
|
||||
"typescript.validate.enable": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "%typescript.validate.enable%"
|
||||
},
|
||||
"typescript.format.insertSpaceAfterCommaDelimiter": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "%format.insertSpaceAfterCommaDelimiter%"
|
||||
},
|
||||
"typescript.format.insertSpaceAfterSemicolonInForStatements": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "%format.insertSpaceAfterSemicolonInForStatements%"
|
||||
},
|
||||
"typescript.format.insertSpaceBeforeAndAfterBinaryOperators": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "%format.insertSpaceBeforeAndAfterBinaryOperators%"
|
||||
},
|
||||
"typescript.format.insertSpaceAfterKeywordsInControlFlowStatements": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "%format.insertSpaceAfterKeywordsInControlFlowStatements%"
|
||||
},
|
||||
"typescript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "%format.insertSpaceAfterFunctionKeywordForAnonymousFunctions%"
|
||||
},
|
||||
"typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "%format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis%"
|
||||
},
|
||||
"typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "%format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets%"
|
||||
},
|
||||
"typescript.format.placeOpenBraceOnNewLineForFunctions": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "%format.placeOpenBraceOnNewLineForFunctions%"
|
||||
},
|
||||
"typescript.format.placeOpenBraceOnNewLineForControlBlocks": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "%format.placeOpenBraceOnNewLineForControlBlocks%"
|
||||
},
|
||||
"javascript.validate.enable": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "%javascript.validate.enable%"
|
||||
},
|
||||
"javascript.format.insertSpaceAfterCommaDelimiter": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "%format.insertSpaceAfterCommaDelimiter%"
|
||||
},
|
||||
"javascript.format.insertSpaceAfterSemicolonInForStatements": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "%format.insertSpaceAfterSemicolonInForStatements%"
|
||||
},
|
||||
"javascript.format.insertSpaceBeforeAndAfterBinaryOperators": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "%format.insertSpaceBeforeAndAfterBinaryOperators%"
|
||||
},
|
||||
"javascript.format.insertSpaceAfterKeywordsInControlFlowStatements": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "%format.insertSpaceAfterKeywordsInControlFlowStatements%"
|
||||
},
|
||||
"javascript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "%format.insertSpaceAfterFunctionKeywordForAnonymousFunctions%"
|
||||
},
|
||||
"javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "%format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis%"
|
||||
},
|
||||
"javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "%format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets%"
|
||||
},
|
||||
"javascript.format.placeOpenBraceOnNewLineForFunctions": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "%format.placeOpenBraceOnNewLineForFunctions%"
|
||||
},
|
||||
"javascript.format.placeOpenBraceOnNewLineForControlBlocks": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "%format.placeOpenBraceOnNewLineForControlBlocks%"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -5,5 +5,14 @@
|
||||
"typescript.useCodeSnippetsOnMethodSuggest.dec": "Complete functions with their parameter signature.",
|
||||
"typescript.tsdk.desc": "Specifies the folder path containing the tsserver and lib*.d.ts files to use.",
|
||||
"typescript.validate.enable": "Enable / disable TypeScript validation",
|
||||
"format.insertSpaceAfterCommaDelimiter": "Defines space handling after a comma delimiter",
|
||||
"format.insertSpaceAfterSemicolonInForStatements": " Defines space handling after a semicolon in a for statement",
|
||||
"format.insertSpaceBeforeAndAfterBinaryOperators": "Defines space handling after a binary operator",
|
||||
"format.insertSpaceAfterKeywordsInControlFlowStatements": "Defines space handling after keywords in control flow statement",
|
||||
"format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": "Defines space handling after function keyword for anonymous functions",
|
||||
"format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": "Defines space handling after opening and before closing non empty parenthesis",
|
||||
"format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": "Defines space handling after opening and before closing non empty brackets",
|
||||
"format.placeOpenBraceOnNewLineForFunctions": "Defines whether an open brace is put onto a new line for functions or not",
|
||||
"format.placeOpenBraceOnNewLineForControlBlocks": "Defines whether an open brace is put onto a new line for control blocks or not",
|
||||
"javascript.validate.enable": "Enable / disable JavaScript validation"
|
||||
}
|
||||
@@ -5,9 +5,8 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import { CompletionItem, TextDocument, Position, CompletionItemKind, CompletionItemProvider, CancellationToken } from 'vscode';
|
||||
import { CompletionItem, TextDocument, Position, CompletionItemKind, CompletionItemProvider, CancellationToken, WorkspaceConfiguration } from 'vscode';
|
||||
|
||||
import { IConfiguration, defaultConfiguration } from './configuration';
|
||||
import { ITypescriptServiceClient } from '../typescriptService';
|
||||
|
||||
import * as PConst from '../protocol.const';
|
||||
@@ -59,6 +58,14 @@ class MyCompletionItem extends CompletionItem {
|
||||
}
|
||||
}
|
||||
|
||||
interface Configuration {
|
||||
useCodeSnippetsOnMethodSuggest?: boolean;
|
||||
}
|
||||
|
||||
namespace Configuration {
|
||||
export const useCodeSnippetsOnMethodSuggest = 'useCodeSnippetsOnMethodSuggest';
|
||||
}
|
||||
|
||||
export default class TypeScriptCompletionItemProvider implements CompletionItemProvider {
|
||||
|
||||
public triggerCharacters = ['.'];
|
||||
@@ -66,15 +73,15 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP
|
||||
public sortBy = [{ type: 'reference', partSeparator: '/' }];
|
||||
|
||||
private client: ITypescriptServiceClient;
|
||||
private config: IConfiguration;
|
||||
private config: Configuration;
|
||||
|
||||
constructor(client: ITypescriptServiceClient) {
|
||||
this.client = client;
|
||||
this.config = defaultConfiguration;
|
||||
this.config = { useCodeSnippetsOnMethodSuggest: false };
|
||||
}
|
||||
|
||||
public setConfiguration(config: IConfiguration): void {
|
||||
this.config = config;
|
||||
public updateConfiguration(config: WorkspaceConfiguration): void {
|
||||
this.config.useCodeSnippetsOnMethodSuggest = config.get(Configuration.useCodeSnippetsOnMethodSuggest, false);
|
||||
}
|
||||
|
||||
public provideCompletionItems(document: TextDocument, position: Position, token: CancellationToken): Promise<CompletionItem[]> {
|
||||
|
||||
@@ -5,21 +5,81 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import { DocumentRangeFormattingEditProvider, OnTypeFormattingEditProvider, FormattingOptions, TextDocument, Position, Range, CancellationToken, TextEdit } from 'vscode';
|
||||
import { DocumentRangeFormattingEditProvider, OnTypeFormattingEditProvider, FormattingOptions, TextDocument, Position, Range, CancellationToken, TextEdit, WorkspaceConfiguration } from 'vscode';
|
||||
|
||||
import * as Proto from '../protocol';
|
||||
import { ITypescriptServiceClient } from '../typescriptService';
|
||||
|
||||
interface Configuration {
|
||||
insertSpaceAfterCommaDelimiter: boolean;
|
||||
insertSpaceAfterSemicolonInForStatements: boolean;
|
||||
insertSpaceBeforeAndAfterBinaryOperators: boolean;
|
||||
insertSpaceAfterKeywordsInControlFlowStatements: boolean;
|
||||
insertSpaceAfterFunctionKeywordForAnonymousFunctions: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: boolean;
|
||||
placeOpenBraceOnNewLineForFunctions: boolean;
|
||||
placeOpenBraceOnNewLineForControlBlocks: boolean;
|
||||
}
|
||||
|
||||
namespace Configuration {
|
||||
export const insertSpaceAfterCommaDelimiter: string = 'insertSpaceAfterCommaDelimiter';
|
||||
export const insertSpaceAfterSemicolonInForStatements: string = 'insertSpaceAfterSemicolonInForStatements';
|
||||
export const insertSpaceBeforeAndAfterBinaryOperators: string = 'insertSpaceBeforeAndAfterBinaryOperators';
|
||||
export const insertSpaceAfterKeywordsInControlFlowStatements: string = 'insertSpaceAfterKeywordsInControlFlowStatements';
|
||||
export const insertSpaceAfterFunctionKeywordForAnonymousFunctions: string = 'insertSpaceAfterFunctionKeywordForAnonymousFunctions';
|
||||
export const insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: string = 'insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis';
|
||||
export const insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: string = 'insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets';
|
||||
export const placeOpenBraceOnNewLineForFunctions: string = 'placeOpenBraceOnNewLineForFunctions';
|
||||
export const placeOpenBraceOnNewLineForControlBlocks: string = 'placeOpenBraceOnNewLineForControlBlocks';
|
||||
|
||||
export function equals(a: Configuration, b: Configuration): boolean {
|
||||
let keys = Object.keys(a);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
let key = keys[i];
|
||||
if (a[key] !== b[key]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export function def(): Configuration {
|
||||
let result: Configuration = Object.create(null);
|
||||
result.insertSpaceAfterCommaDelimiter = true;
|
||||
result.insertSpaceAfterSemicolonInForStatements = true;
|
||||
result.insertSpaceBeforeAndAfterBinaryOperators = true;
|
||||
result.insertSpaceAfterKeywordsInControlFlowStatements = true;
|
||||
result.insertSpaceAfterFunctionKeywordForAnonymousFunctions = false;
|
||||
result.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis = false;
|
||||
result.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets = false;
|
||||
result.placeOpenBraceOnNewLineForFunctions = false;
|
||||
result.placeOpenBraceOnNewLineForControlBlocks = false;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export default class TypeScriptFormattingProvider implements DocumentRangeFormattingEditProvider, OnTypeFormattingEditProvider {
|
||||
|
||||
private client: ITypescriptServiceClient;
|
||||
private config: Configuration;
|
||||
private formatOptions: { [key: string]: Proto.FormatOptions; };
|
||||
|
||||
public constructor(client: ITypescriptServiceClient) {
|
||||
this.client = client;
|
||||
this.config = Configuration.def();
|
||||
this.formatOptions = Object.create(null);
|
||||
}
|
||||
|
||||
public updateConfiguration(config: WorkspaceConfiguration): void {
|
||||
let newConfig = config.get('format', Configuration.def());
|
||||
|
||||
if (!Configuration.equals(this.config, newConfig)) {
|
||||
this.config = newConfig;
|
||||
this.formatOptions = Object.create(null);
|
||||
}
|
||||
}
|
||||
|
||||
private ensureFormatOptions(document: TextDocument, options: FormattingOptions, token: CancellationToken): Promise<Proto.FormatOptions> {
|
||||
let key = document.uri.toString();
|
||||
let currentOptions = this.formatOptions[key];
|
||||
@@ -86,7 +146,17 @@ export default class TypeScriptFormattingProvider implements DocumentRangeFormat
|
||||
indentSize: options.tabSize,
|
||||
convertTabsToSpaces: options.insertSpaces,
|
||||
// We can use \n here since the editor normalizes later on to its line endings.
|
||||
newLineCharacter: '\n'
|
||||
newLineCharacter: '\n' /*,
|
||||
insertSpaceAfterCommaDelimiter: this.config.insertSpaceAfterCommaDelimiter,
|
||||
insertSpaceAfterSemicolonInForStatements: this.config.insertSpaceAfterSemicolonInForStatements,
|
||||
insertSpaceBeforeAndAfterBinaryOperators: this.config.insertSpaceBeforeAndAfterBinaryOperators,
|
||||
insertSpaceAfterKeywordsInControlFlowStatements: this.config.insertSpaceAfterKeywordsInControlFlowStatements,
|
||||
insertSpaceAfterFunctionKeywordForAnonymousFunctions: this.config.insertSpaceAfterFunctionKeywordForAnonymousFunctions,
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: this.config.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis,
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: this.config.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets,
|
||||
placeOpenBraceOnNewLineForFunctions: this.config.placeOpenBraceOnNewLineForFunctions,
|
||||
placeOpenBraceOnNewLineForControlBlocks: this.config.placeOpenBraceOnNewLineForControlBlocks
|
||||
*/
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -15,8 +15,6 @@ import * as Proto from './protocol';
|
||||
import TypeScriptServiceClient from './typescriptServiceClient';
|
||||
import { ITypescriptServiceClientHost } from './typescriptService';
|
||||
|
||||
import * as Configuration from './features/configuration';
|
||||
|
||||
import HoverProvider from './features/hoverProvider';
|
||||
import DefinitionProvider from './features/definitionProvider';
|
||||
import DocumentHighlightProvider from './features/documentHighlightProvider';
|
||||
@@ -69,118 +67,143 @@ export function activate(context: ExtensionContext): void {
|
||||
}));
|
||||
|
||||
window.onDidChangeActiveTextEditor(VersionStatus.showHideStatus, null, context.subscriptions);
|
||||
|
||||
// Register the supports for both TS and TSX so that we can have separate grammars but share the mode
|
||||
client.onReady().then(() => {
|
||||
|
||||
context.subscriptions.push(ProjectStatus.create(client));
|
||||
|
||||
registerSupports(MODE_ID_TS, clientHost, client);
|
||||
registerSupports(MODE_ID_TSX, clientHost, client);
|
||||
registerSupports(MODE_ID_JS, clientHost, client);
|
||||
registerSupports(MODE_ID_JSX, clientHost, client);
|
||||
}, () => {
|
||||
// Nothing to do here. The client did show a message;
|
||||
});
|
||||
}
|
||||
|
||||
function registerSupports(modeID: string, host: TypeScriptServiceClientHost, client: TypeScriptServiceClient) {
|
||||
const validateSetting = 'validate.enable';
|
||||
|
||||
languages.registerHoverProvider(modeID, new HoverProvider(client));
|
||||
languages.registerDefinitionProvider(modeID, new DefinitionProvider(client));
|
||||
languages.registerDocumentHighlightProvider(modeID, new DocumentHighlightProvider(client));
|
||||
languages.registerReferenceProvider(modeID, new ReferenceProvider(client));
|
||||
languages.registerDocumentSymbolProvider(modeID, new DocumentSymbolProvider(client));
|
||||
languages.registerSignatureHelpProvider(modeID, new SignatureHelpProvider(client), '(', ',');
|
||||
languages.registerRenameProvider(modeID, new RenameProvider(client));
|
||||
languages.registerDocumentRangeFormattingEditProvider(modeID, new FormattingProvider(client));
|
||||
languages.registerOnTypeFormattingEditProvider(modeID, new FormattingProvider(client), ';', '}', '\n');
|
||||
languages.registerWorkspaceSymbolProvider(new WorkspaceSymbolProvider(client, modeID));
|
||||
|
||||
languages.setLanguageConfiguration(modeID, {
|
||||
indentationRules: {
|
||||
// ^(.*\*/)?\s*\}.*$
|
||||
decreaseIndentPattern: /^(.*\*\/)?\s*\}.*$/,
|
||||
// ^.*\{[^}"']*$
|
||||
increaseIndentPattern: /^.*\{[^}"']*$/
|
||||
},
|
||||
wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
|
||||
comments: {
|
||||
lineComment: '//',
|
||||
blockComment: ['/*', '*/']
|
||||
},
|
||||
brackets: [
|
||||
['{', '}'],
|
||||
['[', ']'],
|
||||
['(', ')'],
|
||||
],
|
||||
onEnterRules: [
|
||||
{
|
||||
// e.g. /** | */
|
||||
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
|
||||
afterText: /^\s*\*\/$/,
|
||||
action: { indentAction: IndentAction.IndentOutdent, appendText: ' * ' }
|
||||
},
|
||||
{
|
||||
// e.g. /** ...|
|
||||
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
|
||||
action: { indentAction: IndentAction.None, appendText: ' * ' }
|
||||
},
|
||||
{
|
||||
// e.g. * ...|
|
||||
beforeText: /^(\t|(\ \ ))*\ \*(\ ([^\*]|\*(?!\/))*)?$/,
|
||||
action: { indentAction: IndentAction.None, appendText: '* ' }
|
||||
},
|
||||
{
|
||||
// e.g. */|
|
||||
beforeText: /^(\t|(\ \ ))*\ \*\/\s*$/,
|
||||
action: { indentAction: IndentAction.None, removeText: 1 }
|
||||
}
|
||||
],
|
||||
|
||||
__electricCharacterSupport: {
|
||||
docComment: { scope: 'comment.documentation', open: '/**', lineStart: ' * ', close: ' */' }
|
||||
},
|
||||
|
||||
__characterPairSupport: {
|
||||
autoClosingPairs: [
|
||||
{ open: '{', close: '}' },
|
||||
{ open: '[', close: ']' },
|
||||
{ open: '(', close: ')' },
|
||||
{ open: '"', close: '"', notIn: ['string'] },
|
||||
{ open: '\'', close: '\'', notIn: ['string', 'comment'] },
|
||||
{ open: '`', close: '`', notIn: ['string', 'comment'] }
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
// Register suggest support as soon as possible and load configuration lazily
|
||||
let completionItemProvider = new CompletionItemProvider(client);
|
||||
languages.registerCompletionItemProvider(modeID, completionItemProvider, '.');
|
||||
let reloadConfig = () => {
|
||||
completionItemProvider.setConfiguration(Configuration.load(modeID));
|
||||
};
|
||||
workspace.onDidChangeConfiguration(() => {
|
||||
reloadConfig();
|
||||
});
|
||||
reloadConfig();
|
||||
}
|
||||
|
||||
class LanguageManager {
|
||||
class LanguageProvider {
|
||||
|
||||
private description: LanguageDescription;
|
||||
private syntaxDiagnostics: Map<Diagnostic[]>;
|
||||
private currentDiagnostics: DiagnosticCollection;
|
||||
private bufferSyncSupport: BufferSyncSupport;
|
||||
|
||||
private completionItemProvider: CompletionItemProvider;
|
||||
private formattingProvider: FormattingProvider;
|
||||
|
||||
private _validate: boolean;
|
||||
|
||||
constructor(client: TypeScriptServiceClient, description: LanguageDescription, validate: boolean = true) {
|
||||
constructor(client: TypeScriptServiceClient, description: LanguageDescription) {
|
||||
this.description = description;
|
||||
this.bufferSyncSupport = new BufferSyncSupport(client, description.modeIds, validate);
|
||||
this._validate = true;
|
||||
|
||||
this.bufferSyncSupport = new BufferSyncSupport(client, description.modeIds);
|
||||
this.syntaxDiagnostics = Object.create(null);
|
||||
this.currentDiagnostics = languages.createDiagnosticCollection(description.id);
|
||||
this._validate = validate;
|
||||
|
||||
workspace.onDidChangeConfiguration(this.configurationChanged, this);
|
||||
this.configurationChanged();
|
||||
|
||||
client.onReady().then(() => {
|
||||
this.registerProviders(client);
|
||||
}, () => {
|
||||
// Nothing to do here. The client did show a message;
|
||||
});
|
||||
}
|
||||
|
||||
private registerProviders(client: TypeScriptServiceClient): void {
|
||||
let config = workspace.getConfiguration(this.id);
|
||||
|
||||
this.completionItemProvider = new CompletionItemProvider(client);
|
||||
this.completionItemProvider.updateConfiguration(config);
|
||||
|
||||
let hoverProvider = new HoverProvider(client);
|
||||
let definitionProvider = new DefinitionProvider(client);
|
||||
let documentHighlightProvider = new DocumentHighlightProvider(client);
|
||||
let referenceProvider = new ReferenceProvider(client);
|
||||
let documentSymbolProvider = new DocumentSymbolProvider(client);
|
||||
let signatureHelpProvider = new SignatureHelpProvider(client);
|
||||
let renameProvider = new RenameProvider(client);
|
||||
this.formattingProvider = new FormattingProvider(client);
|
||||
this.formattingProvider.updateConfiguration(config);
|
||||
|
||||
this.description.modeIds.forEach(modeId => {
|
||||
languages.registerCompletionItemProvider(modeId, this.completionItemProvider, '.');
|
||||
languages.registerHoverProvider(modeId, hoverProvider);
|
||||
languages.registerDefinitionProvider(modeId, definitionProvider);
|
||||
languages.registerDocumentHighlightProvider(modeId, documentHighlightProvider);
|
||||
languages.registerReferenceProvider(modeId, referenceProvider);
|
||||
languages.registerDocumentSymbolProvider(modeId, documentSymbolProvider);
|
||||
languages.registerSignatureHelpProvider(modeId, signatureHelpProvider, '(', ',');
|
||||
languages.registerRenameProvider(modeId, renameProvider);
|
||||
languages.registerDocumentRangeFormattingEditProvider(modeId, this.formattingProvider);
|
||||
languages.registerOnTypeFormattingEditProvider(modeId, this.formattingProvider, ';', '}', '\n');
|
||||
languages.registerWorkspaceSymbolProvider(new WorkspaceSymbolProvider(client, modeId));
|
||||
languages.setLanguageConfiguration(modeId, {
|
||||
indentationRules: {
|
||||
// ^(.*\*/)?\s*\}.*$
|
||||
decreaseIndentPattern: /^(.*\*\/)?\s*\}.*$/,
|
||||
// ^.*\{[^}"']*$
|
||||
increaseIndentPattern: /^.*\{[^}"']*$/
|
||||
},
|
||||
wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
|
||||
comments: {
|
||||
lineComment: '//',
|
||||
blockComment: ['/*', '*/']
|
||||
},
|
||||
brackets: [
|
||||
['{', '}'],
|
||||
['[', ']'],
|
||||
['(', ')'],
|
||||
],
|
||||
onEnterRules: [
|
||||
{
|
||||
// e.g. /** | */
|
||||
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
|
||||
afterText: /^\s*\*\/$/,
|
||||
action: { indentAction: IndentAction.IndentOutdent, appendText: ' * ' }
|
||||
},
|
||||
{
|
||||
// e.g. /** ...|
|
||||
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
|
||||
action: { indentAction: IndentAction.None, appendText: ' * ' }
|
||||
},
|
||||
{
|
||||
// e.g. * ...|
|
||||
beforeText: /^(\t|(\ \ ))*\ \*(\ ([^\*]|\*(?!\/))*)?$/,
|
||||
action: { indentAction: IndentAction.None, appendText: '* ' }
|
||||
},
|
||||
{
|
||||
// e.g. */|
|
||||
beforeText: /^(\t|(\ \ ))*\ \*\/\s*$/,
|
||||
action: { indentAction: IndentAction.None, removeText: 1 }
|
||||
}
|
||||
],
|
||||
|
||||
__electricCharacterSupport: {
|
||||
docComment: { scope: 'comment.documentation', open: '/**', lineStart: ' * ', close: ' */' }
|
||||
},
|
||||
|
||||
__characterPairSupport: {
|
||||
autoClosingPairs: [
|
||||
{ open: '{', close: '}' },
|
||||
{ open: '[', close: ']' },
|
||||
{ open: '(', close: ')' },
|
||||
{ open: '"', close: '"', notIn: ['string'] },
|
||||
{ open: '\'', close: '\'', notIn: ['string', 'comment'] },
|
||||
{ open: '`', close: '`', notIn: ['string', 'comment'] }
|
||||
]
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private configurationChanged(): void {
|
||||
let config = workspace.getConfiguration(this.id);
|
||||
this.updateValidate(config.get(validateSetting, true));
|
||||
if (this.completionItemProvider) {
|
||||
this.completionItemProvider.updateConfiguration(config);
|
||||
}
|
||||
if (this.formattingProvider) {
|
||||
let formatConfig = config.get('format', {});
|
||||
console.log(formatConfig);
|
||||
this.formattingProvider.updateConfiguration(config);
|
||||
}
|
||||
}
|
||||
|
||||
public handles(file: string): boolean {
|
||||
@@ -191,11 +214,7 @@ class LanguageManager {
|
||||
return this.description.id;
|
||||
}
|
||||
|
||||
public get validate(): boolean {
|
||||
return this._validate;
|
||||
}
|
||||
|
||||
public set validate(value: boolean) {
|
||||
private updateValidate(value: boolean) {
|
||||
if (this._validate === value) {
|
||||
return;
|
||||
}
|
||||
@@ -235,11 +254,10 @@ class LanguageManager {
|
||||
}
|
||||
}
|
||||
|
||||
const validateSetting = 'validate.enable';
|
||||
class TypeScriptServiceClientHost implements ITypescriptServiceClientHost {
|
||||
private client: TypeScriptServiceClient;
|
||||
private languages: LanguageManager[];
|
||||
private languagePerId: Map<LanguageManager>;
|
||||
private languages: LanguageProvider[];
|
||||
private languagePerId: Map<LanguageProvider>;
|
||||
|
||||
constructor(descriptions: LanguageDescription[]) {
|
||||
let handleProjectCreateOrDelete = () => {
|
||||
@@ -260,12 +278,10 @@ class TypeScriptServiceClientHost implements ITypescriptServiceClientHost {
|
||||
this.languages = [];
|
||||
this.languagePerId = Object.create(null);
|
||||
descriptions.forEach(description => {
|
||||
let config = workspace.getConfiguration(description.id);
|
||||
let manager = new LanguageManager(this.client, description, config.get(validateSetting, true));
|
||||
let manager = new LanguageProvider(this.client, description);
|
||||
this.languages.push(manager);
|
||||
this.languagePerId[description.id] = manager;
|
||||
});
|
||||
workspace.onDidChangeConfiguration(this.configurationChanged, this);
|
||||
}
|
||||
|
||||
public get serviceClient(): TypeScriptServiceClient {
|
||||
@@ -277,7 +293,7 @@ class TypeScriptServiceClientHost implements ITypescriptServiceClientHost {
|
||||
this.triggerAllDiagnostics();
|
||||
}
|
||||
|
||||
private findLanguage(file: string): LanguageManager {
|
||||
private findLanguage(file: string): LanguageProvider {
|
||||
for (let i = 0; i < this.languages.length; i++) {
|
||||
let language = this.languages[i];
|
||||
if (language.handles(file)) {
|
||||
@@ -287,13 +303,6 @@ class TypeScriptServiceClientHost implements ITypescriptServiceClientHost {
|
||||
return null;
|
||||
}
|
||||
|
||||
private configurationChanged(): void {
|
||||
this.languages.forEach(language => {
|
||||
let config = workspace.getConfiguration(language.id);
|
||||
language.validate = config.get(validateSetting, true);
|
||||
});
|
||||
}
|
||||
|
||||
private triggerAllDiagnostics() {
|
||||
Object.keys(this.languagePerId).forEach(key => this.languagePerId[key].triggerAllDiagnostics());
|
||||
}
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
"target": "es5",
|
||||
"module": "commonjs",
|
||||
"sourceMap": true,
|
||||
"outDir": "../out"
|
||||
"sourceRoot": "../src",
|
||||
"outDir": "./out"
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"server"
|
||||
"server",
|
||||
"out"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user