mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 12:19:20 +00:00
html: polish reading of settings
This commit is contained in:
@@ -12,7 +12,7 @@ import {
|
|||||||
} from './languageModes';
|
} from './languageModes';
|
||||||
|
|
||||||
export function getHTMLMode(htmlLanguageService: HTMLLanguageService, workspace: Workspace): LanguageMode {
|
export function getHTMLMode(htmlLanguageService: HTMLLanguageService, workspace: Workspace): LanguageMode {
|
||||||
let htmlDocuments = getLanguageModelCache<HTMLDocument>(10, 60, document => htmlLanguageService.parseHTMLDocument(document));
|
const htmlDocuments = getLanguageModelCache<HTMLDocument>(10, 60, document => htmlLanguageService.parseHTMLDocument(document));
|
||||||
return {
|
return {
|
||||||
getId() {
|
getId() {
|
||||||
return 'html';
|
return 'html';
|
||||||
@@ -21,15 +21,13 @@ export function getHTMLMode(htmlLanguageService: HTMLLanguageService, workspace:
|
|||||||
return htmlLanguageService.getSelectionRanges(document, [position])[0];
|
return htmlLanguageService.getSelectionRanges(document, [position])[0];
|
||||||
},
|
},
|
||||||
doComplete(document: TextDocument, position: Position, documentContext: DocumentContext, settings = workspace.settings) {
|
doComplete(document: TextDocument, position: Position, documentContext: DocumentContext, settings = workspace.settings) {
|
||||||
let options = settings && settings.html && settings.html.suggest;
|
const htmlSettings = settings?.html;
|
||||||
let doAutoComplete = settings && settings.html && settings.html.autoClosingTags;
|
const options = merge(htmlSettings?.suggest, {});
|
||||||
if (doAutoComplete) {
|
options.hideAutoCompleteProposals = htmlSettings?.autoClosingTags === true;
|
||||||
options.hideAutoCompleteProposals = true;
|
options.attributeDefaultValue = htmlSettings?.completion?.attributeDefaultValue ?? 'doublequotes';
|
||||||
}
|
|
||||||
options.attributeDefaultValue = settings.html.completion.attributeDefaultValue ?? 'doublequotes';
|
|
||||||
|
|
||||||
const htmlDocument = htmlDocuments.get(document);
|
const htmlDocument = htmlDocuments.get(document);
|
||||||
let completionList = htmlLanguageService.doComplete2(document, position, htmlDocument, documentContext, options);
|
const completionList = htmlLanguageService.doComplete2(document, position, htmlDocument, documentContext, options);
|
||||||
return completionList;
|
return completionList;
|
||||||
},
|
},
|
||||||
async doHover(document: TextDocument, position: Position, settings?: Settings) {
|
async doHover(document: TextDocument, position: Position, settings?: Settings) {
|
||||||
@@ -45,26 +43,21 @@ export function getHTMLMode(htmlLanguageService: HTMLLanguageService, workspace:
|
|||||||
return htmlLanguageService.findDocumentSymbols(document, htmlDocuments.get(document));
|
return htmlLanguageService.findDocumentSymbols(document, htmlDocuments.get(document));
|
||||||
},
|
},
|
||||||
async format(document: TextDocument, range: Range, formatParams: FormattingOptions, settings = workspace.settings) {
|
async format(document: TextDocument, range: Range, formatParams: FormattingOptions, settings = workspace.settings) {
|
||||||
let formatSettings: HTMLFormatConfiguration = settings && settings.html && settings.html.format;
|
const formatSettings: HTMLFormatConfiguration = merge(settings?.html?.format, {});
|
||||||
if (formatSettings) {
|
|
||||||
formatSettings = merge(formatSettings, {});
|
|
||||||
} else {
|
|
||||||
formatSettings = {};
|
|
||||||
}
|
|
||||||
if (formatSettings.contentUnformatted) {
|
if (formatSettings.contentUnformatted) {
|
||||||
formatSettings.contentUnformatted = formatSettings.contentUnformatted + ',script';
|
formatSettings.contentUnformatted = formatSettings.contentUnformatted + ',script';
|
||||||
} else {
|
} else {
|
||||||
formatSettings.contentUnformatted = 'script';
|
formatSettings.contentUnformatted = 'script';
|
||||||
}
|
}
|
||||||
formatSettings = merge(formatParams, formatSettings);
|
merge(formatParams, formatSettings);
|
||||||
return htmlLanguageService.format(document, range, formatSettings);
|
return htmlLanguageService.format(document, range, formatSettings);
|
||||||
},
|
},
|
||||||
async getFoldingRanges(document: TextDocument): Promise<FoldingRange[]> {
|
async getFoldingRanges(document: TextDocument): Promise<FoldingRange[]> {
|
||||||
return htmlLanguageService.getFoldingRanges(document);
|
return htmlLanguageService.getFoldingRanges(document);
|
||||||
},
|
},
|
||||||
async doAutoClose(document: TextDocument, position: Position) {
|
async doAutoClose(document: TextDocument, position: Position) {
|
||||||
let offset = document.offsetAt(position);
|
const offset = document.offsetAt(position);
|
||||||
let text = document.getText();
|
const text = document.getText();
|
||||||
if (offset > 0 && text.charAt(offset - 1).match(/[>\/]/g)) {
|
if (offset > 0 && text.charAt(offset - 1).match(/[>\/]/g)) {
|
||||||
return htmlLanguageService.doTagComplete(document, position, htmlDocuments.get(document));
|
return htmlLanguageService.doTagComplete(document, position, htmlDocuments.get(document));
|
||||||
}
|
}
|
||||||
@@ -92,9 +85,11 @@ export function getHTMLMode(htmlLanguageService: HTMLLanguageService, workspace:
|
|||||||
}
|
}
|
||||||
|
|
||||||
function merge(src: any, dst: any): any {
|
function merge(src: any, dst: any): any {
|
||||||
for (const key in src) {
|
if (src) {
|
||||||
if (src.hasOwnProperty(key)) {
|
for (const key in src) {
|
||||||
dst[key] = src[key];
|
if (src.hasOwnProperty(key)) {
|
||||||
|
dst[key] = src[key];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return dst;
|
return dst;
|
||||||
|
|||||||
Reference in New Issue
Block a user