html.format.enable

This commit is contained in:
Johannes Rieken 2016-10-17 15:30:11 +02:00
parent db48473d51
commit 2d9d187f5b
3 changed files with 48 additions and 22 deletions

View file

@ -6,7 +6,7 @@
import * as path from 'path';
import { languages, ExtensionContext, IndentAction } from 'vscode';
import { languages, workspace, ExtensionContext, IndentAction } from 'vscode';
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } from 'vscode-languageclient';
import { EMPTY_ELEMENTS } from './htmlEmptyTagsShared';
@ -36,6 +36,7 @@ export function activate(context: ExtensionContext) {
configurationSection: ['html'],
},
initializationOptions: {
['format.enable']: workspace.getConfiguration('html').get('format.enable')
}
};

View file

@ -18,25 +18,56 @@
"install-client-next": "npm install vscode-languageclient@next -f -S",
"install-client-local": "npm install ../../../vscode-languageserver-node/client -f -S"
},
"contributes": {
"languages": [{
"id": "html",
"extensions": [ ".html", ".htm", ".shtml", ".xhtml", ".mdoc", ".jsp", ".asp", ".aspx", ".jshtm", ".vue" ],
"aliases": [ "HTML", "htm", "html", "xhtml" ],
"mimetypes": ["text/html", "text/x-jshtm", "text/template", "text/ng-template", "application/xhtml+xml"],
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "html",
"scopeName": "text.html.basic",
"path": "./syntaxes/html.json"
}],
"contributes": {
"languages": [
{
"id": "html",
"extensions": [
".html",
".htm",
".shtml",
".xhtml",
".mdoc",
".jsp",
".asp",
".aspx",
".jshtm",
".vue"
],
"aliases": [
"HTML",
"htm",
"html",
"xhtml"
],
"mimetypes": [
"text/html",
"text/x-jshtm",
"text/template",
"text/ng-template",
"application/xhtml+xml"
],
"configuration": "./language-configuration.json"
}
],
"grammars": [
{
"language": "html",
"scopeName": "text.html.basic",
"path": "./syntaxes/html.json"
}
],
"configuration": {
"id": "html",
"order": 20,
"type": "object",
"title": "HTML",
"properties": {
"html.format.enable": {
"type": "boolean",
"default": true,
"description": "Enable/disable default HTML formatter"
},
"html.format.wrapLineLength": {
"type": "integer",
"default": 120,
@ -108,4 +139,4 @@
"vscode-languageclient": "^2.6.0-next.1",
"vscode-nls": "^1.0.7"
}
}
}

View file

@ -48,8 +48,7 @@ connection.onInitialize((params: InitializeParams): InitializeResult => {
textDocumentSync: documents.syncKind,
completionProvider: { resolveProvider: false, triggerCharacters: ['.', ':', '<', '"', '=', '/'] },
documentHighlightProvider: true,
documentRangeFormattingProvider: true,
documentFormattingProvider: true,
documentRangeFormattingProvider: params.initializationOptions['format.enable'],
documentLinkProvider: true
}
};
@ -106,11 +105,6 @@ function getFormattingOptions(formatParams: FormattingOptions) {
return merge(formatParams, merge(formatSettings, {}));
}
connection.onDocumentFormatting(formatParams => {
let document = documents.get(formatParams.textDocument.uri);
return languageService.format(document, null, getFormattingOptions(formatParams.options));
});
connection.onDocumentRangeFormatting(formatParams => {
let document = documents.get(formatParams.textDocument.uri);
return languageService.format(document, formatParams.range, getFormattingOptions(formatParams.options));