mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
[html] Formatting JavaScript placed after div elements inside html file adds 12 extra tabs. Fixes #23063
This commit is contained in:
parent
4f07618a8d
commit
1242ff5751
|
@ -13,7 +13,7 @@ export interface LanguageRange extends Range {
|
|||
}
|
||||
|
||||
export interface HTMLDocumentRegions {
|
||||
getEmbeddedDocument(languageId: string): TextDocument;
|
||||
getEmbeddedDocument(languageId: string, ignoreAttributeValues?: boolean): TextDocument;
|
||||
getLanguageRanges(range: Range): LanguageRange[];
|
||||
getLanguageAtPosition(position: Position): string;
|
||||
getLanguagesInDocument(): string[];
|
||||
|
@ -83,7 +83,7 @@ export function getDocumentRegions(languageService: LanguageService, document: T
|
|||
}
|
||||
return {
|
||||
getLanguageRanges: (range: Range) => getLanguageRanges(document, regions, range),
|
||||
getEmbeddedDocument: (languageId: string) => getEmbeddedDocument(document, regions, languageId),
|
||||
getEmbeddedDocument: (languageId: string, ignoreAttributeValues: boolean) => getEmbeddedDocument(document, regions, languageId, ignoreAttributeValues),
|
||||
getLanguageAtPosition: (position: Position) => getLanguageAtPosition(document, regions, position),
|
||||
getLanguagesInDocument: () => getLanguagesInDocument(document, regions),
|
||||
getImportedScripts: () => importedScripts
|
||||
|
@ -160,13 +160,13 @@ function getLanguageAtPosition(document: TextDocument, regions: EmbeddedRegion[]
|
|||
return 'html';
|
||||
}
|
||||
|
||||
function getEmbeddedDocument(document: TextDocument, contents: EmbeddedRegion[], languageId: string): TextDocument {
|
||||
function getEmbeddedDocument(document: TextDocument, contents: EmbeddedRegion[], languageId: string, ignoreAttributeValues: boolean): TextDocument {
|
||||
let currentPos = 0;
|
||||
let oldContent = document.getText();
|
||||
let result = '';
|
||||
let lastSuffix = '';
|
||||
for (let c of contents) {
|
||||
if (c.languageId === languageId) {
|
||||
if (c.languageId === languageId && (!ignoreAttributeValues || !c.attributeValue)) {
|
||||
result = substituteWithWhitespace(result, currentPos, c.start, oldContent, lastSuffix, getPrefix(c));
|
||||
result += oldContent.substring(c.start, c.end);
|
||||
currentPos = c.end;
|
||||
|
|
|
@ -241,7 +241,9 @@ export function getJavascriptMode(documentRegions: LanguageModelCache<HTMLDocume
|
|||
return null;
|
||||
},
|
||||
format(document: TextDocument, range: Range, formatParams: FormattingOptions): TextEdit[] {
|
||||
updateCurrentTextDocument(document);
|
||||
currentTextDocument = documentRegions.get(document).getEmbeddedDocument('javascript', true);
|
||||
scriptFileVersion++;
|
||||
|
||||
let initialIndentLevel = computeInitialIndent(document, range, formatParams);
|
||||
let formatSettings = convertOptions(formatParams, settings && settings.format, initialIndentLevel + 1);
|
||||
let start = currentTextDocument.offsetAt(range.start);
|
||||
|
|
6
extensions/html/server/src/test/fixtures/expected/21634.html
vendored
Normal file
6
extensions/html/server/src/test/fixtures/expected/21634.html
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
<app-route path="/module" element="page-module" bindRouter onUrlChange="updateModel"></app-route>
|
||||
<script>
|
||||
Polymer({
|
||||
});
|
||||
|
||||
</script>
|
6
extensions/html/server/src/test/fixtures/inputs/21634.html
vendored
Normal file
6
extensions/html/server/src/test/fixtures/inputs/21634.html
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
<app-route path="/module" element="page-module" bindRouter onUrlChange="updateModel"></app-route>
|
||||
|
||||
<script>
|
||||
Polymer({
|
||||
});
|
||||
</script>
|
|
@ -71,6 +71,7 @@ suite('HTML Embedded Formatting', () => {
|
|||
assertFormatWithFixture('19813.html', '19813.html');
|
||||
assertFormatWithFixture('19813.html', '19813-4spaces.html', void 0, FormattingOptions.create(4, true));
|
||||
assertFormatWithFixture('19813.html', '19813-tab.html', void 0, FormattingOptions.create(1, false));
|
||||
assertFormatWithFixture('21634.html', '21634.html');
|
||||
})
|
||||
|
||||
test('Script end tag', function (): any {
|
||||
|
|
Loading…
Reference in a new issue