Skip to content

Commit ebc43b3

Browse files
committed
Merge remote-tracking branch 'origin/master' into alex/tokenization
2 parents 68b8ad5 + 4496c87 commit ebc43b3

200 files changed

Lines changed: 4322 additions & 2337 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build/gulpfile.vscode.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const nodeModules = ['electron', 'original-fs']
4040

4141
const builtInExtensions = [
4242
{ name: 'ms-vscode.node-debug', version: '1.9.0' },
43-
{ name: 'ms-vscode.node-debug2', version: '1.9.0' }
43+
{ name: 'ms-vscode.node-debug2', version: '1.9.1' }
4444
];
4545

4646
const vscodeEntryPoints = _.flatten([
@@ -110,7 +110,7 @@ const config = {
110110
version: packageJson.electronVersion,
111111
productAppName: product.nameLong,
112112
companyName: 'Microsoft Corporation',
113-
copyright: 'Copyright (C) 2016 Microsoft. All rights reserved',
113+
copyright: 'Copyright (C) 2017 Microsoft. All rights reserved',
114114
darwinIcon: 'resources/darwin/code.icns',
115115
darwinBundleIdentifier: product.darwinBundleIdentifier,
116116
darwinApplicationCategoryType: 'public.app-category.developer-tools',

extensions/cpp/syntaxes/c.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,6 @@
318318
{
319319
"include": "#preprocessor-rule-other-block"
320320
},
321-
{
322-
"include": "#sizeof"
323-
},
324321
{
325322
"include": "#access"
326323
},
@@ -458,7 +455,7 @@
458455
"line_continuation_character": {
459456
"patterns": [
460457
{
461-
"match": "(\\\\)\\s*\\n",
458+
"match": "(\\\\)\\n",
462459
"captures": {
463460
"1": {
464461
"name": "constant.character.escape.line-continuation.c"
@@ -891,6 +888,15 @@
891888
}
892889
},
893890
"patterns": [
891+
{
892+
"include": "#access"
893+
},
894+
{
895+
"include": "#libc"
896+
},
897+
{
898+
"include": "#c_function_call"
899+
},
894900
{
895901
"include": "$self"
896902
}
@@ -976,5 +982,5 @@
976982
]
977983
}
978984
},
979-
"version": "https://github.com/atom/language-c/commit/2a5fafe1d86f690b5ab2c877cea2fc6a598e001a"
985+
"version": "https://github.com/atom/language-c/commit/0d0f32388e73fc91a86f4c31ff59c36191869d63"
980986
}

extensions/html/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,16 @@
141141
"default": true,
142142
"description": "%html.suggest.html5.desc%"
143143
},
144+
"html.validate.scripts": {
145+
"type": "boolean",
146+
"default": true,
147+
"description": "%html.validate.scripts%"
148+
},
149+
"html.validate.styles": {
150+
"type": "boolean",
151+
"default": true,
152+
"description": "%html.validate.styles%"
153+
},
144154
"html.trace.server": {
145155
"type": "string",
146156
"enum": [

extensions/html/package.nls.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@
1010
"html.format.extraLiners.desc": "List of tags, comma separated, that should have an extra newline before them. 'null' defaults to \"head, body, /html\".",
1111
"html.suggest.angular1.desc": "Configures if the built-in HTML language support suggests Angular V1 tags and properties.",
1212
"html.suggest.ionic.desc": "Configures if the built-in HTML language support suggests Ionic tags, properties and values.",
13-
"html.suggest.html5.desc":"Configures if the built-in HTML language support suggests HTML5 tags, properties and values."
13+
"html.suggest.html5.desc":"Configures if the built-in HTML language support suggests HTML5 tags, properties and values.",
14+
"html.validate.scripts": "Configures if the built-in HTML language support validates embedded scripts.",
15+
"html.validate.styles": "Configures if the built-in HTML language support validates embedded styles."
1416
}

extensions/html/server/src/htmlServerMain.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
import { createConnection, IConnection, TextDocuments, InitializeParams, InitializeResult, RequestType } from 'vscode-languageserver';
88
import { DocumentContext } from 'vscode-html-languageservice';
9-
import { TextDocument, Diagnostic, DocumentLink, Range, TextEdit, SymbolInformation } from 'vscode-languageserver-types';
9+
import { TextDocument, Diagnostic, DocumentLink, Range, SymbolInformation } from 'vscode-languageserver-types';
1010
import { getLanguageModes, LanguageModes } from './modes/languageModes';
1111

12+
import { format } from './modes/formatting';
13+
1214
import * as url from 'url';
1315
import * as path from 'path';
1416
import uri from 'vscode-uri';
@@ -69,9 +71,18 @@ connection.onInitialize((params: InitializeParams): InitializeResult => {
6971
};
7072
});
7173

74+
let validation = {
75+
html: true,
76+
css: true,
77+
javascript: true
78+
};
79+
7280
// The settings have changed. Is send on server activation as well.
7381
connection.onDidChangeConfiguration((change) => {
7482
settings = change.settings;
83+
let validationSettings = settings && settings.html && settings.html.validate || {};
84+
validation.css = validationSettings.styles !== false;
85+
validation.javascript = validationSettings.scripts !== false;
7586

7687
languageModes.getAllModes().forEach(m => {
7788
if (m.configure) {
@@ -115,7 +126,7 @@ function triggerValidation(textDocument: TextDocument): void {
115126
function validateTextDocument(textDocument: TextDocument): void {
116127
let diagnostics: Diagnostic[] = [];
117128
languageModes.getAllModesInDocument(textDocument).forEach(mode => {
118-
if (mode.doValidation) {
129+
if (mode.doValidation && validation[mode.getId()]) {
119130
pushAll(diagnostics, mode.doValidation(textDocument));
120131
}
121132
});
@@ -201,18 +212,11 @@ connection.onSignatureHelp(signatureHelpParms => {
201212

202213
connection.onDocumentRangeFormatting(formatParams => {
203214
let document = documents.get(formatParams.textDocument.uri);
204-
let ranges = languageModes.getModesInRange(document, formatParams.range);
205-
let result: TextEdit[] = [];
215+
206216
let unformattedTags: string = settings && settings.html && settings.html.format && settings.html.format.unformatted || '';
207-
let enabledModes = { css: !unformattedTags.match(/\bstyle\b/), javascript: !unformattedTags.match(/\bscript\b/), html: true };
208-
ranges.forEach(r => {
209-
let mode = r.mode;
210-
if (mode && mode.format && enabledModes[mode.getId()] && !r.attributeValue) {
211-
let edits = mode.format(document, r, formatParams.options);
212-
pushAll(result, edits);
213-
}
214-
});
215-
return result;
217+
let enabledModes = { css: !unformattedTags.match(/\bstyle\b/), javascript: !unformattedTags.match(/\bscript\b/) };
218+
219+
return format(languageModes, document, formatParams.range, formatParams.options, enabledModes);
216220
});
217221

218222
connection.onDocumentLinks(documentLinkParam => {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
'use strict';
6+
7+
import { applyEdits } from '../utils/edits';
8+
import { TextDocument, Range, TextEdit, FormattingOptions } from 'vscode-languageserver-types';
9+
import { LanguageModes } from './languageModes';
10+
11+
export function format(languageModes: LanguageModes, document: TextDocument, formatRange: Range, formattingOptions: FormattingOptions, enabledModes: { [mode: string]: boolean }) {
12+
// run the html formatter on the full range and pass the result content to the embedded formatters.
13+
// from the final content create a single edit
14+
// advantages of this approach are
15+
// - correct indents in the html document
16+
// - correct initial indent for embedded formatters
17+
// - no worrying of overlapping edits
18+
19+
// perform a html format and apply changes to a new document
20+
let htmlMode = languageModes.getMode('html');
21+
let htmlEdits = htmlMode.format(document, formatRange, formattingOptions);
22+
let htmlFormattedContent = applyEdits(document, htmlEdits);
23+
let newDocument = TextDocument.create(document.uri + '.tmp', document.languageId, document.version, htmlFormattedContent);
24+
try {
25+
// run embedded formatters on html formatted content: - formatters see correct initial indent
26+
let afterFormatRangeLength = document.getText().length - document.offsetAt(formatRange.end); // length of unchanged content after replace range
27+
let newFormatRange = Range.create(formatRange.start, newDocument.positionAt(htmlFormattedContent.length - afterFormatRangeLength));
28+
let embeddedRanges = languageModes.getModesInRange(newDocument, newFormatRange);
29+
30+
let embeddedEdits: TextEdit[] = [];
31+
32+
for (let r of embeddedRanges) {
33+
let mode = r.mode;
34+
if (mode && mode.format && enabledModes[mode.getId()] && !r.attributeValue) {
35+
let edits = mode.format(newDocument, r, formattingOptions);
36+
for (let edit of edits) {
37+
embeddedEdits.push(edit);
38+
}
39+
}
40+
};
41+
42+
if (embeddedEdits.length === 0) {
43+
return htmlEdits;
44+
}
45+
46+
// apply all embedded format edits and create a single edit for all changes
47+
let resultContent = applyEdits(newDocument, embeddedEdits);
48+
let resultReplaceText = resultContent.substring(document.offsetAt(formatRange.start), resultContent.length - afterFormatRangeLength);
49+
50+
return [TextEdit.replace(formatRange, resultReplaceText)];
51+
} finally {
52+
languageModes.onDocumentRemoved(newDocument);
53+
}
54+
55+
}

extensions/html/server/src/modes/htmlMode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function getHTMLMode(htmlLanguageService: HTMLLanguageService): LanguageM
2020
settings = options && options.html;
2121
},
2222
doComplete(document: TextDocument, position: Position) {
23-
let options = settings && settings.html && settings.html.suggest;
23+
let options = settings && settings.suggest;
2424
return htmlLanguageService.doComplete(document, position, htmlDocuments.get(document), options);
2525
},
2626
doHover(document: TextDocument, position: Position) {

extensions/html/server/src/test/formatting.test.ts

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import * as assert from 'assert';
88
import { getLanguageModes } from '../modes/languageModes';
99
import { TextDocument, Range, TextEdit, FormattingOptions } from 'vscode-languageserver-types';
1010

11+
import { format } from '../modes/formatting';
12+
1113
suite('HTML Embedded Formatting', () => {
1214

1315
function assertFormat(value: string, expected: string, options?: any): void {
@@ -31,15 +33,8 @@ suite('HTML Embedded Formatting', () => {
3133
let range = Range.create(document.positionAt(rangeStartOffset), document.positionAt(rangeEndOffset));
3234
let formatOptions = FormattingOptions.create(2, true);
3335

34-
let ranges = languageModes.getModesInRange(document, range);
35-
let result: TextEdit[] = [];
36-
ranges.forEach(r => {
37-
let mode = r.mode;
38-
if (mode && mode.format) {
39-
let edits = mode.format(document, r, formatOptions);
40-
pushAll(result, edits);
41-
}
42-
});
36+
let result = format(languageModes, document, range, formatOptions, { css: true, javascript: true });
37+
4338
let actual = applyEdits(document, result);
4439
assert.equal(actual, expected);
4540
}
@@ -52,38 +47,38 @@ suite('HTML Embedded Formatting', () => {
5247

5348
test('HTML & Scripts', function (): any {
5449
assertFormat('<html><head><script></script></head></html>', '<html>\n\n<head>\n <script></script>\n</head>\n\n</html>');
55-
assertFormat('<html><head><script>var x=1;</script></head></html>', '<html>\n\n<head>\n <script>var x = 1;</script>\n</head>\n\n</html>');
56-
assertFormat('<html><head><script>\nvar x=2;\n</script></head></html>', '<html>\n\n<head>\n <script>\n var x = 2;\n</script>\n</head>\n\n</html>');
57-
assertFormat('<html><head>\n <script>\nvar x=3;\n</script></head></html>', '<html>\n\n<head>\n <script>\n var x = 3;\n </script>\n</head>\n\n</html>');
58-
assertFormat('<html><head>\n <script>\nvar x=4;\nconsole.log("Hi");\n</script></head></html>', '<html>\n\n<head>\n <script>\n var x = 4;\n console.log("Hi");\n </script>\n</head>\n\n</html>');
50+
assertFormat('<html><head><script>var x=1;</script></head></html>', '<html>\n\n<head>\n <script>\n var x = 1;\n </script>\n</head>\n\n</html>');
51+
assertFormat('<html><head><script>\nvar x=2;\n</script></head></html>', '<html>\n\n<head>\n <script>\n var x = 2;\n\n </script>\n</head>\n\n</html>');
52+
assertFormat('<html><head>\n <script>\nvar x=3;\n</script></head></html>', '<html>\n\n<head>\n <script>\n var x = 3;\n\n </script>\n</head>\n\n</html>');
53+
assertFormat('<html><head>\n <script>\nvar x=4;\nconsole.log("Hi");\n</script></head></html>', '<html>\n\n<head>\n <script>\n var x = 4;\n console.log("Hi");\n\n </script>\n</head>\n\n</html>');
5954

60-
assertFormat('<html><head>\n |<script>\nvar x=5;\n</script>|</head></html>', '<html><head>\n <script>\n var x = 5;\n </script></head></html>');
55+
assertFormat('<html><head>\n |<script>\nvar x=5;\n</script>|</head></html>', '<html><head>\n <script>\n var x = 5;\n\n </script></head></html>');
6156
assertFormat('<html><head>\n <script>\n|var x=6;|\n</script></head></html>', '<html><head>\n <script>\n var x = 6;\n</script></head></html>');
6257
});
6358

6459
test('Script end tag', function (): any {
65-
assertFormat('<html>\n<head>\n <script>\nvar x = 0;\n</script></head></html>', '<html>\n\n<head>\n <script>\n var x = 0;\n </script>\n</head>\n\n</html>');
60+
assertFormat('<html>\n<head>\n <script>\nvar x = 0;\n</script></head></html>', '<html>\n\n<head>\n <script>\n var x = 0;\n\n </script>\n</head>\n\n</html>');
6661
});
6762

6863
test('HTML & Multiple Scripts', function (): any {
69-
assertFormat('<html><head>\n<script>\nif(x){\nbar(); }\n</script><script>\nfunction(x){}\n</script></head></html>', '<html>\n\n<head>\n <script>\n if (x) {\n bar();\n }\n</script>\n<script>\n function(x) { }\n</script>\n</head>\n\n</html>');
64+
assertFormat('<html><head>\n<script>\nif(x){\nbar(); }\n</script><script>\nfunction(x){}\n</script></head></html>', '<html>\n\n<head>\n <script>\n if (x) {\n bar();\n }\n\n </script>\n <script>\n function(x) { }\n\n </script>\n</head>\n\n</html>');
7065
});
7166

7267
test('HTML & Styles', function (): any {
73-
assertFormat('<html><head>\n<style>\n.foo{display:none;}\n</style></head></html>', '<html>\n\n<head>\n <style>\n.foo{display:none;}\n</style>\n</head>\n\n</html>');
68+
assertFormat('<html><head>\n<style>\n.foo{display:none;}\n</style></head></html>', '<html>\n\n<head>\n <style>\n .foo {\n display: none;\n }\n </style>\n</head>\n\n</html>');
7469
});
7570

7671
test('EndWithNewline', function (): any {
7772
let options = {
7873
html: {
7974
format: {
80-
endWithNewline : true
75+
endWithNewline: true
8176
}
8277
}
8378
};
8479
assertFormat('<html><body><p>Hello</p></body></html>', '<html>\n\n<body>\n <p>Hello</p>\n</body>\n\n</html>\n', options);
8580
assertFormat('<html>|<body><p>Hello</p></body>|</html>', '<html><body>\n <p>Hello</p>\n</body></html>', options);
86-
assertFormat('<html><head><script>\nvar x=1;\n</script></head></html>', '<html>\n\n<head>\n <script>\n var x = 1;\n</script>\n</head>\n\n</html>\n', options);
81+
assertFormat('<html><head><script>\nvar x=1;\n</script></head></html>', '<html>\n\n<head>\n <script>\n var x = 1;\n\n </script>\n</head>\n\n</html>\n', options);
8782
});
8883

8984
});
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
'use strict';
6+
7+
import { TextDocument, TextEdit, Position } from 'vscode-languageserver-types';
8+
9+
export function applyEdits(document: TextDocument, edits: TextEdit[]): string {
10+
let text = document.getText();
11+
let sortedEdits = edits.sort((a, b) => {
12+
let startDiff = comparePositions(a.range.start, b.range.start);
13+
if (startDiff === 0) {
14+
return comparePositions(a.range.end, b.range.end);
15+
}
16+
return startDiff;
17+
});
18+
let lastOffset = text.length;
19+
sortedEdits.forEach(e => {
20+
let startOffset = document.offsetAt(e.range.start);
21+
let endOffset = document.offsetAt(e.range.end);
22+
text = text.substring(0, startOffset) + e.newText + text.substring(endOffset, text.length);
23+
lastOffset = startOffset;
24+
});
25+
return text;
26+
}
27+
28+
function comparePositions(p1: Position, p2: Position) {
29+
let diff = p2.line - p1.line;
30+
if (diff === 0) {
31+
return p2.character - p1.character;
32+
}
33+
return diff;
34+
}

extensions/javascript/src/features/packageJSONContribution.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class PackageJSONContribution implements IJSONContribution {
6767
let name = keys[0];
6868
let insertText = new SnippetString().appendText(JSON.stringify(name));
6969
if (addValue) {
70-
insertText.appendText(': ').appendPlaceholder('*');
70+
insertText.appendText(': "').appendPlaceholder('').appendText('"');
7171
if (!isLast) {
7272
insertText.appendText(',');
7373
}
@@ -99,7 +99,7 @@ export class PackageJSONContribution implements IJSONContribution {
9999
this.mostDependedOn.forEach((name) => {
100100
let insertText = new SnippetString().appendText(JSON.stringify(name));
101101
if (addValue) {
102-
insertText.appendText(': ').appendPlaceholder('*');
102+
insertText.appendText(': "').appendPlaceholder('').appendText('"');
103103
if (!isLast) {
104104
insertText.appendText(',');
105105
}

0 commit comments

Comments
 (0)