volar-service-html
Advanced tools
Comparing version 0.0.47 to 0.0.48
@@ -1,2 +0,2 @@ | ||
import type { Disposable, DocumentSelector, FormattingOptions, ProviderResult, ServiceContext, LanguageServicePlugin } from '@volar/language-service'; | ||
import type { Disposable, DocumentSelector, FormattingOptions, ProviderResult, LanguageServiceContext, LanguageServicePlugin } from '@volar/language-service'; | ||
import * as html from 'vscode-html-languageservice'; | ||
@@ -9,15 +9,15 @@ import { TextDocument } from 'vscode-languageserver-textdocument'; | ||
} | ||
export declare function create({ documentSelector, useDefaultDataProvider, getDocumentContext, isFormattingEnabled, isAutoCreateQuotesEnabled, isAutoClosingTagsEnabled, getFormattingOptions, getCompletionConfiguration, getHoverSettings, getCustomData, onDidChangeCustomData, }?: { | ||
export declare function create({ documentSelector, useDefaultDataProvider, getDocumentContext, isFormattingEnabled, getFormattingOptions, getCompletionConfiguration, getHoverSettings, getCustomData, onDidChangeCustomData, }?: { | ||
documentSelector?: DocumentSelector; | ||
useDefaultDataProvider?: boolean; | ||
isFormattingEnabled?(document: TextDocument, context: ServiceContext): ProviderResult<boolean>; | ||
isAutoCreateQuotesEnabled?(document: TextDocument, context: ServiceContext): ProviderResult<boolean>; | ||
isAutoClosingTagsEnabled?(document: TextDocument, context: ServiceContext): ProviderResult<boolean>; | ||
getDocumentContext?(context: ServiceContext): html.DocumentContext; | ||
getFormattingOptions?(document: TextDocument, options: FormattingOptions, context: ServiceContext): ProviderResult<html.HTMLFormatConfiguration>; | ||
getCompletionConfiguration?(document: TextDocument, context: ServiceContext): ProviderResult<html.CompletionConfiguration | undefined>; | ||
getHoverSettings?(document: TextDocument, context: ServiceContext): ProviderResult<html.HoverSettings | undefined>; | ||
getCustomData?(context: ServiceContext): ProviderResult<html.IHTMLDataProvider[]>; | ||
onDidChangeCustomData?(listener: () => void, context: ServiceContext): Disposable; | ||
isFormattingEnabled?(document: TextDocument, context: LanguageServiceContext): ProviderResult<boolean>; | ||
isAutoCreateQuotesEnabled?(document: TextDocument, context: LanguageServiceContext): ProviderResult<boolean>; | ||
isAutoClosingTagsEnabled?(document: TextDocument, context: LanguageServiceContext): ProviderResult<boolean>; | ||
getDocumentContext?(context: LanguageServiceContext): html.DocumentContext; | ||
getFormattingOptions?(document: TextDocument, options: FormattingOptions, context: LanguageServiceContext): ProviderResult<html.HTMLFormatConfiguration>; | ||
getCompletionConfiguration?(document: TextDocument, context: LanguageServiceContext): ProviderResult<html.CompletionConfiguration | undefined>; | ||
getHoverSettings?(document: TextDocument, context: LanguageServiceContext): ProviderResult<html.HoverSettings | undefined>; | ||
getCustomData?(context: LanguageServiceContext): ProviderResult<html.IHTMLDataProvider[]>; | ||
onDidChangeCustomData?(listener: () => void, context: LanguageServiceContext): Disposable; | ||
}): LanguageServicePlugin; | ||
//# sourceMappingURL=index.d.ts.map |
76
index.js
@@ -10,5 +10,6 @@ "use strict"; | ||
resolveReference(ref, base) { | ||
const decoded = context.decodeEmbeddedDocumentUri(base); | ||
let baseUri = vscode_uri_1.URI.parse(base); | ||
const decoded = context.decodeEmbeddedDocumentUri(baseUri); | ||
if (decoded) { | ||
base = decoded[0]; | ||
baseUri = decoded[0]; | ||
} | ||
@@ -19,4 +20,4 @@ if (ref.match(/^\w[\w\d+.-]*:/)) { | ||
} | ||
if (ref[0] === '/') { // resolve absolute path against the current workspace folder | ||
let folderUri = context.env.workspaceFolder; | ||
if (ref[0] === '/' && context.env.workspaceFolders.length) { // resolve absolute path against the current workspace folder | ||
let folderUri = context.env.workspaceFolders[0].toString(); | ||
if (!folderUri.endsWith('/')) { | ||
@@ -27,3 +28,2 @@ folderUri += '/'; | ||
} | ||
const baseUri = vscode_uri_1.URI.parse(base); | ||
const baseUriDir = baseUri.path.endsWith('/') ? baseUri : vscode_uri_1.Utils.dirname(baseUri); | ||
@@ -35,6 +35,2 @@ return vscode_uri_1.Utils.resolvePath(baseUriDir, ref).toString(true); | ||
return await context.env.getConfiguration?.('html.format.enable') ?? true; | ||
}, isAutoCreateQuotesEnabled = async (_document, context) => { | ||
return await context.env.getConfiguration?.('html.autoCreateQuotes') ?? true; | ||
}, isAutoClosingTagsEnabled = async (_document, context) => { | ||
return await context.env.getConfiguration?.('html.autoClosingTags') ?? true; | ||
}, getFormattingOptions = async (_document, options, context) => { | ||
@@ -62,12 +58,15 @@ const formatSettings = { | ||
for (const customDataPath of customData) { | ||
const uri = vscode_uri_1.Utils.resolvePath(vscode_uri_1.URI.parse(context.env.workspaceFolder), customDataPath); | ||
const json = await context.env.fs?.readFile?.(uri.toString()); | ||
if (json) { | ||
try { | ||
const data = JSON.parse(json); | ||
newData.push(html.newHTMLDataProvider(customDataPath, data)); | ||
for (const workspaceFolder of context.env.workspaceFolders) { | ||
const uri = vscode_uri_1.Utils.resolvePath(workspaceFolder, customDataPath); | ||
const json = await context.env.fs?.readFile?.(uri); | ||
if (json) { | ||
try { | ||
const data = JSON.parse(json); | ||
newData.push(html.newHTMLDataProvider(customDataPath, data)); | ||
} | ||
catch (error) { | ||
console.error(error); | ||
} | ||
break; | ||
} | ||
catch (error) { | ||
console.error(error); | ||
} | ||
} | ||
@@ -84,12 +83,39 @@ } | ||
}, } = {}) { | ||
const configurationSections = { | ||
autoCreateQuotes: 'html.autoCreateQuotes', | ||
autoClosingTags: 'html.autoClosingTags', | ||
}; | ||
return { | ||
name: 'html', | ||
// https://github.com/microsoft/vscode/blob/09850876e652688fb142e2e19fd00fd38c0bc4ba/extensions/html-language-features/server/src/htmlServer.ts#L183 | ||
triggerCharacters: ['.', ':', '<', '"', '=', '/'], | ||
capabilities: { | ||
completionProvider: { | ||
// https://github.com/microsoft/vscode/blob/09850876e652688fb142e2e19fd00fd38c0bc4ba/extensions/html-language-features/server/src/htmlServer.ts#L183 | ||
triggerCharacters: ['.', ':', '<', '"', '=', '/'], | ||
}, | ||
renameProvider: { | ||
prepareProvider: true, | ||
}, | ||
hoverProvider: true, | ||
documentHighlightProvider: true, | ||
documentLinkProvider: {}, | ||
documentSymbolProvider: true, | ||
foldingRangeProvider: true, | ||
selectionRangeProvider: true, | ||
documentFormattingProvider: true, | ||
linkedEditingRangeProvider: true, | ||
autoInsertionProvider: { | ||
triggerCharacters: ['=', '>', '/'], | ||
configurationSections: [ | ||
configurationSections.autoCreateQuotes, | ||
configurationSections.autoClosingTags, | ||
configurationSections.autoClosingTags, | ||
], | ||
}, | ||
}, | ||
create(context) { | ||
const htmlDocuments = new WeakMap(); | ||
const fileSystemProvider = { | ||
stat: async (uri) => await context.env.fs?.stat(uri) | ||
stat: async (uri) => await context.env.fs?.stat(vscode_uri_1.URI.parse(uri)) | ||
?? { type: html.FileType.Unknown, ctime: 0, mtime: 0, size: 0 }, | ||
readDirectory: async (uri) => await context.env.fs?.readDirectory(uri) ?? [], | ||
readDirectory: async (uri) => await context.env.fs?.readDirectory(vscode_uri_1.URI.parse(uri)) ?? [], | ||
}; | ||
@@ -276,3 +302,3 @@ const documentContext = getDocumentContext(context); | ||
}, | ||
async provideAutoInsertionEdit(document, selection, change) { | ||
async provideAutoInsertSnippet(document, selection, change) { | ||
// selection must at end of change | ||
@@ -284,3 +310,3 @@ if (document.offsetAt(selection) !== change.rangeOffset + change.text.length) { | ||
if (change.rangeLength === 0 && change.text.endsWith('=')) { | ||
const enabled = await isAutoCreateQuotesEnabled(document, context); | ||
const enabled = await context.env.getConfiguration?.('html.autoCreateQuotes') ?? true; | ||
if (enabled) { | ||
@@ -295,3 +321,3 @@ const completionConfiguration = await getCompletionConfiguration(document, context); | ||
if (change.rangeLength === 0 && (change.text.endsWith('>') || change.text.endsWith('/'))) { | ||
const enabled = await isAutoClosingTagsEnabled(document, context); | ||
const enabled = await context.env.getConfiguration?.('html.autoClosingTags') ?? true; | ||
if (enabled) { | ||
@@ -298,0 +324,0 @@ const text = htmlLs.doTagComplete(document, selection, htmlDocument); |
{ | ||
"name": "volar-service-html", | ||
"version": "0.0.47", | ||
"version": "0.0.48", | ||
"description": "Integrate vscode-languageservice-html into Volar", | ||
@@ -35,3 +35,3 @@ "homepage": "https://github.com/volarjs/services/tree/master/packages/html", | ||
"peerDependencies": { | ||
"@volar/language-service": "~2.2.3" | ||
"@volar/language-service": "~2.3.0-alpha.0" | ||
}, | ||
@@ -43,3 +43,3 @@ "peerDependenciesMeta": { | ||
}, | ||
"gitHead": "d53f4dfa7007e77409af3ef28cc165e9940e7313" | ||
"gitHead": "6a80c92133e154907a79eefa05603f63994214c3" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23373
391