Skip to content

Commit a785671

Browse files
committed
html: polish reading of settings
1 parent 8d70e04 commit a785671

File tree

1 file changed

+15
-20
lines changed
  • extensions/html-language-features/server/src/modes

1 file changed

+15
-20
lines changed

extensions/html-language-features/server/src/modes/htmlMode.ts

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from './languageModes';
1313

1414
export function getHTMLMode(htmlLanguageService: HTMLLanguageService, workspace: Workspace): LanguageMode {
15-
let htmlDocuments = getLanguageModelCache<HTMLDocument>(10, 60, document => htmlLanguageService.parseHTMLDocument(document));
15+
const htmlDocuments = getLanguageModelCache<HTMLDocument>(10, 60, document => htmlLanguageService.parseHTMLDocument(document));
1616
return {
1717
getId() {
1818
return 'html';
@@ -21,15 +21,13 @@ export function getHTMLMode(htmlLanguageService: HTMLLanguageService, workspace:
2121
return htmlLanguageService.getSelectionRanges(document, [position])[0];
2222
},
2323
doComplete(document: TextDocument, position: Position, documentContext: DocumentContext, settings = workspace.settings) {
24-
let options = settings && settings.html && settings.html.suggest;
25-
let doAutoComplete = settings && settings.html && settings.html.autoClosingTags;
26-
if (doAutoComplete) {
27-
options.hideAutoCompleteProposals = true;
28-
}
29-
options.attributeDefaultValue = settings.html.completion.attributeDefaultValue ?? 'doublequotes';
24+
const htmlSettings = settings?.html;
25+
const options = merge(htmlSettings?.suggest, {});
26+
options.hideAutoCompleteProposals = htmlSettings?.autoClosingTags === true;
27+
options.attributeDefaultValue = htmlSettings?.completion?.attributeDefaultValue ?? 'doublequotes';
3028

3129
const htmlDocument = htmlDocuments.get(document);
32-
let completionList = htmlLanguageService.doComplete2(document, position, htmlDocument, documentContext, options);
30+
const completionList = htmlLanguageService.doComplete2(document, position, htmlDocument, documentContext, options);
3331
return completionList;
3432
},
3533
async doHover(document: TextDocument, position: Position, settings?: Settings) {
@@ -45,26 +43,21 @@ export function getHTMLMode(htmlLanguageService: HTMLLanguageService, workspace:
4543
return htmlLanguageService.findDocumentSymbols(document, htmlDocuments.get(document));
4644
},
4745
async format(document: TextDocument, range: Range, formatParams: FormattingOptions, settings = workspace.settings) {
48-
let formatSettings: HTMLFormatConfiguration = settings && settings.html && settings.html.format;
49-
if (formatSettings) {
50-
formatSettings = merge(formatSettings, {});
51-
} else {
52-
formatSettings = {};
53-
}
46+
const formatSettings: HTMLFormatConfiguration = merge(settings?.html?.format, {});
5447
if (formatSettings.contentUnformatted) {
5548
formatSettings.contentUnformatted = formatSettings.contentUnformatted + ',script';
5649
} else {
5750
formatSettings.contentUnformatted = 'script';
5851
}
59-
formatSettings = merge(formatParams, formatSettings);
52+
merge(formatParams, formatSettings);
6053
return htmlLanguageService.format(document, range, formatSettings);
6154
},
6255
async getFoldingRanges(document: TextDocument): Promise<FoldingRange[]> {
6356
return htmlLanguageService.getFoldingRanges(document);
6457
},
6558
async doAutoClose(document: TextDocument, position: Position) {
66-
let offset = document.offsetAt(position);
67-
let text = document.getText();
59+
const offset = document.offsetAt(position);
60+
const text = document.getText();
6861
if (offset > 0 && text.charAt(offset - 1).match(/[>\/]/g)) {
6962
return htmlLanguageService.doTagComplete(document, position, htmlDocuments.get(document));
7063
}
@@ -92,9 +85,11 @@ export function getHTMLMode(htmlLanguageService: HTMLLanguageService, workspace:
9285
}
9386

9487
function merge(src: any, dst: any): any {
95-
for (const key in src) {
96-
if (src.hasOwnProperty(key)) {
97-
dst[key] = src[key];
88+
if (src) {
89+
for (const key in src) {
90+
if (src.hasOwnProperty(key)) {
91+
dst[key] = src[key];
92+
}
9893
}
9994
}
10095
return dst;

0 commit comments

Comments
 (0)