Skip to content

Commit

Permalink
chore: update to Volar 2.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Jun 22, 2024
1 parent a9cecea commit b0d24c5
Show file tree
Hide file tree
Showing 25 changed files with 141 additions and 141 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@lerna-lite/publish": "latest",
"@tsslint/cli": "latest",
"@tsslint/config": "latest",
"@volar/language-service": "~2.3.0",
"@volar/language-service": "~2.3.1",
"typescript": "latest"
}
}
2 changes: 1 addition & 1 deletion packages/css/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@types/node": "latest"
},
"peerDependencies": {
"@volar/language-service": "~2.3.0"
"@volar/language-service": "~2.3.1"
},
"peerDependenciesMeta": {
"@volar/language-service": {
Expand Down
2 changes: 1 addition & 1 deletion packages/emmet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@types/node": "latest"
},
"peerDependencies": {
"@volar/language-service": "~2.3.0"
"@volar/language-service": "~2.3.1"
},
"peerDependenciesMeta": {
"@volar/language-service": {
Expand Down
2 changes: 1 addition & 1 deletion packages/html/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@types/node": "latest"
},
"peerDependencies": {
"@volar/language-service": "~2.3.0"
"@volar/language-service": "~2.3.1"
},
"peerDependenciesMeta": {
"@volar/language-service": {
Expand Down
2 changes: 1 addition & 1 deletion packages/json/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"vscode-languageserver-textdocument": "^1.0.11"
},
"peerDependencies": {
"@volar/language-service": "~2.3.0"
"@volar/language-service": "~2.3.1"
},
"peerDependenciesMeta": {
"@volar/language-service": {
Expand Down
2 changes: 1 addition & 1 deletion packages/markdown/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"vscode-languageserver-textdocument": "^1.0.11"
},
"peerDependencies": {
"@volar/language-service": "~2.3.0"
"@volar/language-service": "~2.3.1"
},
"peerDependenciesMeta": {
"@volar/language-service": {
Expand Down
2 changes: 1 addition & 1 deletion packages/prettier/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"prettier": "^3.0.3"
},
"peerDependencies": {
"@volar/language-service": "~2.3.0",
"@volar/language-service": "~2.3.1",
"prettier": "^2.2 || ^3.0"
},
"peerDependenciesMeta": {
Expand Down
2 changes: 1 addition & 1 deletion packages/prettyhtml/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@starptech/prettyhtml": "^0.10.0"
},
"peerDependencies": {
"@volar/language-service": "~2.3.0"
"@volar/language-service": "~2.3.1"
},
"peerDependenciesMeta": {
"@volar/language-service": {
Expand Down
2 changes: 1 addition & 1 deletion packages/pug-beautify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@johnsoncodehk/pug-beautify": "^0.2.2"
},
"peerDependencies": {
"@volar/language-service": "~2.3.0"
"@volar/language-service": "~2.3.1"
},
"peerDependenciesMeta": {
"@volar/language-service": {
Expand Down
7 changes: 4 additions & 3 deletions packages/pug/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Diagnostic, DiagnosticSeverity, Disposable, DocumentSelector, ProviderResult, LanguageServiceContext, LanguageServicePlugin, LanguageServicePluginInstance } from '@volar/language-service';
import type { Diagnostic, DiagnosticSeverity, Disposable, DocumentSelector, LanguageServiceContext, LanguageServicePlugin, LanguageServicePluginInstance, ProviderResult } from '@volar/language-service';
import { transformDocumentSymbol } from '@volar/language-service';
import { getSourceRange } from '@volar/language-service/lib/utils/featureWorkers';
import { create as createHtmlService } from 'volar-service-html';
import type * as html from 'vscode-html-languageservice';
import type { TextDocument } from 'vscode-languageserver-textdocument';
Expand Down Expand Up @@ -111,10 +112,10 @@ export function create({
provideDocumentSymbols(document, token) {
return worker(document, async pugDoc => {

const htmlResult = await htmlService.provideDocumentSymbols?.(pugDoc.map.embeddedDocument, token) ?? [];
const htmlResult = await htmlService.provideDocumentSymbols?.(pugDoc.docs[1], token) ?? [];
const pugResult = htmlResult.map(htmlSymbol => transformDocumentSymbol(
htmlSymbol,
range => pugDoc.map.getSourceRange(range)
range => getSourceRange(pugDoc.docs, range)
)).filter((symbol): symbol is NonNullable<typeof symbol> => symbol !== undefined);

return pugResult;
Expand Down
14 changes: 7 additions & 7 deletions packages/pug/lib/pugDocument.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SourceMap, SourceMapWithDocuments } from '@volar/language-service';
import { defaultMapperFactory } from '@volar/language-service';
import type { DocumentsAndMap } from '@volar/language-service/lib/utils/featureWorkers';
import type * as html from 'vscode-html-languageservice';
import { TextDocument } from 'vscode-languageserver-textdocument';
import { baseParse } from './baseParse';
Expand All @@ -11,18 +12,17 @@ export function register(htmlLs: html.LanguageService) {

const parsed = baseParse(pugCode);
const htmlTextDocument = TextDocument.create('foo.html', 'html', 0, parsed.htmlCode);
const sourceMap = new SourceMapWithDocuments(
const htmlDocument = htmlLs.parseHTMLDocument(htmlTextDocument);
const docs: DocumentsAndMap = [
parsed.pugTextDocument,
htmlTextDocument,
new SourceMap(parsed.mappings),
);
const htmlDocument = htmlLs.parseHTMLDocument(htmlTextDocument);
defaultMapperFactory(parsed.mappings),
];

return {
...parsed,
htmlTextDocument,
htmlDocument,
map: sourceMap,
docs,
};
};
}
44 changes: 21 additions & 23 deletions packages/pug/lib/services/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type * as html from 'vscode-html-languageservice';
import { TextDocument } from 'vscode-html-languageservice';
import type { PugDocument } from '../pugDocument';
import { LanguageServiceContext, transformCompletionList } from '@volar/language-service';
import { getGeneratedPositions, getSourceRange } from '@volar/language-service/lib/utils/featureWorkers';

export function register(htmlLs: html.LanguageService) {

Expand Down Expand Up @@ -33,29 +34,26 @@ export function register(htmlLs: html.LanguageService) {
return htmlComplete;
}

const htmlPos = pugDoc.map.getGeneratedPosition(pos);
if (!htmlPos) {
return;
}
for (const htmlPos of getGeneratedPositions(pugDoc.docs, pos)) {
const htmlComplete = documentContext ? await htmlLs.doComplete2(
pugDoc.docs[1],
htmlPos,
pugDoc.htmlDocument,
documentContext,
options
) : htmlLs.doComplete(
pugDoc.docs[1],
htmlPos,
pugDoc.htmlDocument,
options
);

const htmlComplete = documentContext ? await htmlLs.doComplete2(
pugDoc.htmlTextDocument,
htmlPos,
pugDoc.htmlDocument,
documentContext,
options
) : htmlLs.doComplete(
pugDoc.htmlTextDocument,
htmlPos,
pugDoc.htmlDocument,
options
);

return transformCompletionList(
htmlComplete,
htmlRange => pugDoc.map.getSourceRange(htmlRange),
pugDoc.map.embeddedDocument,
serviceContext
);
return transformCompletionList(
htmlComplete,
htmlRange => getSourceRange(pugDoc.docs, htmlRange),
pugDoc.docs[1],
serviceContext
);
}
};
}
27 changes: 13 additions & 14 deletions packages/pug/lib/services/documentHighlight.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import { transformLocations } from '@volar/language-service';
import { getGeneratedPositions, getSourceRange } from '@volar/language-service/lib/utils/featureWorkers';
import type * as html from 'vscode-html-languageservice';
import type { PugDocument } from '../pugDocument';
import { transformLocations } from '@volar/language-service';

export function register(htmlLs: html.LanguageService) {
return (pugDoc: PugDocument, pos: html.Position) => {

const htmlPos = pugDoc.map.getGeneratedPosition(pos);
if (!htmlPos) {
return;
}
for (const htmlPos of getGeneratedPositions(pugDoc.docs, pos)) {

const htmlResult = htmlLs.findDocumentHighlights(
pugDoc.map.embeddedDocument,
htmlPos,
pugDoc.htmlDocument
);
const htmlResult = htmlLs.findDocumentHighlights(
pugDoc.docs[1],
htmlPos,
pugDoc.htmlDocument
);

return transformLocations(
htmlResult,
htmlRange => pugDoc.map.getSourceRange(htmlRange)
);
return transformLocations(
htmlResult,
htmlRange => getSourceRange(pugDoc.docs, htmlRange)
);
}
};
}
7 changes: 4 additions & 3 deletions packages/pug/lib/services/documentLinks.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { transformLocations } from '@volar/language-service';
import { getSourceRange } from '@volar/language-service/lib/utils/featureWorkers';
import type * as html from 'vscode-html-languageservice';
import type { PugDocument } from '../pugDocument';
import { transformLocations } from '@volar/language-service';

export function register(htmlLs: html.LanguageService) {
return (pugDoc: PugDocument, docContext: html.DocumentContext) => {

const htmlResult = htmlLs.findDocumentLinks(
pugDoc.map.embeddedDocument,
pugDoc.docs[1],
docContext
);

return transformLocations(
htmlResult,
htmlRange => pugDoc.map.getSourceRange(htmlRange)
htmlRange => getSourceRange(pugDoc.docs, htmlRange)
);
};
}
29 changes: 14 additions & 15 deletions packages/pug/lib/services/hover.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import { transformHover } from '@volar/language-service';
import { getGeneratedPositions, getSourceRange } from '@volar/language-service/lib/utils/featureWorkers';
import type * as html from 'vscode-html-languageservice';
import type { PugDocument } from '../pugDocument';
import { transformHover } from '@volar/language-service';

export function register(htmlLs: html.LanguageService) {
return (pugDoc: PugDocument, pos: html.Position, options?: html.HoverSettings | undefined) => {

const htmlPos = pugDoc.map.getGeneratedPosition(pos);
if (!htmlPos) {
return;
}
for (const htmlPos of getGeneratedPositions(pugDoc.docs, pos)) {

const htmlResult = htmlLs.doHover(
pugDoc.map.embeddedDocument,
htmlPos,
pugDoc.htmlDocument,
options
);
if (!htmlResult) {
return;
}
const htmlResult = htmlLs.doHover(
pugDoc.docs[1],
htmlPos,
pugDoc.htmlDocument,
options
);
if (!htmlResult) {
return;
}

return transformHover(htmlResult, htmlRange => pugDoc.map.getSourceRange(htmlRange));
return transformHover(htmlResult, htmlRange => getSourceRange(pugDoc.docs, htmlRange));
}
};
}
21 changes: 10 additions & 11 deletions packages/pug/lib/services/quoteComplete.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import { getGeneratedPositions } from '@volar/language-service/lib/utils/featureWorkers';
import type * as html from 'vscode-html-languageservice';
import type { PugDocument } from '../pugDocument';

export function register(htmlLs: html.LanguageService) {
return (pugDoc: PugDocument, pos: html.Position, options?: html.CompletionConfiguration | undefined) => {

const htmlStart = pugDoc.map.getGeneratedPosition(pos);
if (!htmlStart) {
return;
}
for (const htmlStart of getGeneratedPositions(pugDoc.docs, pos)) {

const text = htmlLs.doQuoteComplete(
pugDoc.htmlTextDocument,
htmlStart,
pugDoc.htmlDocument,
options
);
const text = htmlLs.doQuoteComplete(
pugDoc.docs[1],
htmlStart,
pugDoc.htmlDocument,
options
);

return text;
return text;
}
};
}
8 changes: 4 additions & 4 deletions packages/pug/lib/services/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { PugDocument } from '../pugDocument';
export function register(htmlLs: html.LanguageService) {
return (pugDoc: PugDocument, initialOffset = 0) => {

const htmlOffset = pugDoc.map.map.mappings
const htmlOffset = pugDoc.docs[2].mappings
.filter(mapping => mapping.sourceOffsets[0] >= initialOffset)
.sort((a, b) => a.generatedOffsets[0] - b.generatedOffsets[0])[0]
?.generatedOffsets[0];
Expand All @@ -13,21 +13,21 @@ export function register(htmlLs: html.LanguageService) {
return;
}

const htmlScanner = htmlLs.createScanner(pugDoc.htmlTextDocument.getText(), htmlOffset);
const htmlScanner = htmlLs.createScanner(pugDoc.docs[1].getText(), htmlOffset);

// @ts-expect-error
const scanner: html.Scanner = {
scan: () => {
return htmlScanner.scan();
},
getTokenOffset: () => {
for (const [offset] of pugDoc.map.map.getSourceOffsets(htmlScanner.getTokenOffset())) {
for (const [offset] of pugDoc.docs[2].toSourceLocation(htmlScanner.getTokenOffset())) {
return offset;
}
return -1;
},
getTokenEnd: () => {
for (const [offset] of pugDoc.map.map.getSourceOffsets(htmlScanner.getTokenEnd())) {
for (const [offset] of pugDoc.docs[2].toSourceLocation(htmlScanner.getTokenEnd())) {
return offset;
}
return -1;
Expand Down
11 changes: 8 additions & 3 deletions packages/pug/lib/services/selectionRanges.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import type * as html from 'vscode-html-languageservice';
import type { PugDocument } from '../pugDocument';
import { transformLocations } from '@volar/language-service';
import { getGeneratedPositions, getSourceRange } from '@volar/language-service/lib/utils/featureWorkers';

export function register(htmlLs: html.LanguageService) {
return (pugDoc: PugDocument, posArr: html.Position[]) => {

const htmlPosArr = posArr
.map(position => pugDoc.map.getGeneratedPosition(position))
.map(position => {
for (const pos of getGeneratedPositions(pugDoc.docs, position)) {
return pos;
}
})
.filter((v): v is NonNullable<typeof v> => !!v);

const htmlResult = htmlLs.getSelectionRanges(
pugDoc.map.embeddedDocument,
pugDoc.docs[1],
htmlPosArr
);

return transformLocations(htmlResult, htmlRange => pugDoc.map.getSourceRange(htmlRange));
return transformLocations(htmlResult, htmlRange => getSourceRange(pugDoc.docs, htmlRange));
};
}
2 changes: 1 addition & 1 deletion packages/pug/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"url": "https://github.com/johnsoncodehk"
},
"dependencies": {
"@volar/language-service": "~2.3.0",
"@volar/language-service": "~2.3.1",
"muggle-string": "^0.4.1",
"pug-lexer": "^5.0.1",
"pug-parser": "^6.0.0",
Expand Down
Loading

0 comments on commit b0d24c5

Please sign in to comment.