mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-23 03:39:23 +00:00
Update html-language-features to use doQuoteComplete
This commit is contained in:
@@ -34,6 +34,10 @@ namespace CustomDataContent {
|
||||
export const type: RequestType<string, string, any> = new RequestType('html/customDataContent');
|
||||
}
|
||||
|
||||
namespace QuoteCreateRequest {
|
||||
export const type: RequestType<TextDocumentPositionParams, string, any> = new RequestType('html/quote');
|
||||
}
|
||||
|
||||
namespace TagCloseRequest {
|
||||
export const type: RequestType<TextDocumentPositionParams, string | null, any> = new RequestType('html/tag');
|
||||
}
|
||||
@@ -83,7 +87,7 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment)
|
||||
let workspaceFoldersSupport = false;
|
||||
let foldingRangeLimit = Number.MAX_VALUE;
|
||||
|
||||
const customDataRequestService : CustomDataRequestService = {
|
||||
const customDataRequestService: CustomDataRequestService = {
|
||||
getContent(uri: string) {
|
||||
return connection.sendRequest(CustomDataContent.type, uri);
|
||||
}
|
||||
@@ -483,6 +487,22 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment)
|
||||
}, [], `Error while computing color presentations for ${params.textDocument.uri}`, token);
|
||||
});
|
||||
|
||||
connection.onRequest(QuoteCreateRequest.type, (params, token) => {
|
||||
return runSafe(runtime, async () => {
|
||||
const document = documents.get(params.textDocument.uri);
|
||||
if (document) {
|
||||
const pos = params.position;
|
||||
if (pos.character > 0) {
|
||||
const mode = languageModes.getModeAtPosition(document, Position.create(pos.line, pos.character - 1));
|
||||
if (mode && mode.doAutoQuote) {
|
||||
return mode.doAutoQuote(document, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}, null, `Error while computing tag close actions for ${params.textDocument.uri}`, token);
|
||||
});
|
||||
|
||||
connection.onRequest(TagCloseRequest.type, (params, token) => {
|
||||
return runSafe(runtime, async () => {
|
||||
const document = documents.get(params.textDocument.uri);
|
||||
|
||||
@@ -55,6 +55,18 @@ export function getHTMLMode(htmlLanguageService: HTMLLanguageService, workspace:
|
||||
async getFoldingRanges(document: TextDocument): Promise<FoldingRange[]> {
|
||||
return htmlLanguageService.getFoldingRanges(document);
|
||||
},
|
||||
async doAutoQuote(document: TextDocument, position: Position, settings = workspace.settings) {
|
||||
const htmlSettings = settings?.html;
|
||||
const options = merge(htmlSettings?.suggest, {});
|
||||
options.attributeDefaultValue = htmlSettings?.completion?.attributeDefaultValue ?? 'doublequotes';
|
||||
|
||||
const offset = document.offsetAt(position);
|
||||
const text = document.getText();
|
||||
if (offset > 0 && text.charAt(offset - 1) === '=') {
|
||||
return htmlLanguageService.doQuoteComplete(document, position, htmlDocuments.get(document), options);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
async doAutoClose(document: TextDocument, position: Position) {
|
||||
const offset = document.offsetAt(position);
|
||||
const text = document.getText();
|
||||
|
||||
@@ -72,6 +72,7 @@ export interface LanguageMode {
|
||||
format?: (document: TextDocument, range: Range, options: FormattingOptions, settings?: Settings) => Promise<TextEdit[]>;
|
||||
findDocumentColors?: (document: TextDocument) => Promise<ColorInformation[]>;
|
||||
getColorPresentations?: (document: TextDocument, color: Color, range: Range) => Promise<ColorPresentation[]>;
|
||||
doAutoQuote?: (document: TextDocument, position: Position) => Promise<string | null>;
|
||||
doAutoClose?: (document: TextDocument, position: Position) => Promise<string | null>;
|
||||
findMatchingTagPosition?: (document: TextDocument, position: Position) => Promise<Position | null>;
|
||||
getFoldingRanges?: (document: TextDocument) => Promise<FoldingRange[]>;
|
||||
|
||||
Reference in New Issue
Block a user