Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rewrite @volar/vue-typescript #1050

Merged
merged 22 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d55d04c
refactor: remove TextDocument depend for `compileTemplate`
johnsoncodehk Mar 15, 2022
8a37435
chore: remove unused `getHtmlDocument`
johnsoncodehk Mar 15, 2022
a174619
refactor: move away api proxy from tsRuntime
johnsoncodehk Mar 16, 2022
9e96ba6
chore: faster test
johnsoncodehk Mar 16, 2022
6f01809
refactor: move away documents from tsRuntime
johnsoncodehk Mar 16, 2022
7d4d53d
refactor: move away `@volar/typescript-language-service` depend from …
johnsoncodehk Mar 16, 2022
ea98a61
chore: update pnpm-lock.yaml
johnsoncodehk Mar 16, 2022
95dc1a9
refactor: move fileSystemProvide to language server
johnsoncodehk Mar 16, 2022
cb7f47b
chore: use TextRange instance of `[number, number]`
johnsoncodehk Mar 16, 2022
4213b23
refactor: move away language services from `@volar/vue-typescript`
johnsoncodehk Mar 16, 2022
2beb709
chore: fix test
johnsoncodehk Mar 16, 2022
1510f55
refactor: move away `loadCustomPlugins` from `@volar/vue-language-ser…
johnsoncodehk Mar 16, 2022
11ab386
refactor: move templateComplete to plugins
johnsoncodehk Mar 16, 2022
972f7e3
chore: move `cssClasses.ts` to `@volar/vue-language-service`
johnsoncodehk Mar 16, 2022
5e01713
refactor: move documentContext to `@volar/vue-language-service`
johnsoncodehk Mar 16, 2022
c81b6e5
refactor: donate my life
johnsoncodehk Mar 17, 2022
ea7dceb
chore: vueDocument.ts -> vueDocuments.ts
johnsoncodehk Mar 17, 2022
5919c23
refactor: unused `shared.createPathMap` in vue-typescript
johnsoncodehk Mar 17, 2022
215c3d5
refactor: remove LSP depends in ts pkgs
johnsoncodehk Mar 17, 2022
b6e4c28
chore: organize imports
johnsoncodehk Mar 17, 2022
94aabcc
chore: small adjustment
johnsoncodehk Mar 17, 2022
5e9de43
fix: revert pug baseParse changes
johnsoncodehk Mar 17, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions extensions/vscode-vue-language-features/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -634,13 +634,12 @@
"@volar/shared": "0.33.2",
"@volar/vue-language-server": "0.33.2",
"@vue/compiler-dom": "^3.2.27",
"@vue/compiler-sfc": "^3.2.27",
"@vue/reactivity": "^3.2.27",
"esbuild": "latest",
"upath": "^2.0.1",
"vsce": "latest",
"vscode-html-languageservice": "^4.2.1",
"vscode-languageclient": "^8.0.0-next.8",
"vscode-languageserver-textdocument": "^1.0.3",
"vscode-nls": "5.0.0"
}
}
16 changes: 8 additions & 8 deletions extensions/vscode-vue-language-features/src/features/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { compile, NodeTypes } from '@vue/compiler-dom';
import * as path from 'upath';
import * as fs from '../utils/fs';
import * as shared from '@volar/shared';
import { TextDocument } from 'vscode-languageserver-textdocument';
import { htmlLs, userPick } from './splitEditors';
import { userPick } from './splitEditors';
import { parse } from '@vue/compiler-sfc';

interface PreviewState { port: number, fileName: string }

Expand Down Expand Up @@ -213,8 +213,8 @@ export async function activate(context: vscode.ExtensionContext) {
if (req !== goToTemplateReq)
return;

const sfc = shared.parseSfc(doc.getText(), htmlLs.parseHTMLDocument(TextDocument.create(doc.uri.toString(), doc.languageId, doc.version, doc.getText())));
const offset = sfc.template?.startTagEnd ?? 0;
const sfc = parse(doc.getText(), { sourceMap: false, ignoreEmpty: false });
const offset = sfc.descriptor.template?.loc.start.offset ?? 0;
const start = doc.positionAt(data.range[0] + offset);
const end = doc.positionAt(data.range[1] + offset);
await vscode.window.showTextDocument(doc, vscode.ViewColumn.One);
Expand Down Expand Up @@ -273,13 +273,13 @@ export async function activate(context: vscode.ExtensionContext) {

function createQuery(vueCode: string, fileName: string) {

const sfc = shared.parseSfc(vueCode, htmlLs.parseHTMLDocument(TextDocument.create('', '', 0, vueCode)));
const sfc = parse(vueCode, { sourceMap: false, ignoreEmpty: false });
let query = '';

for (const customBlock of sfc.customBlocks) {
for (const customBlock of sfc.descriptor.customBlocks) {
if (customBlock.type === 'preview') {
const previewTagStart = vueCode.substring(0, customBlock.startTagEnd).lastIndexOf('<preview');
const previewTag = vueCode.substring(previewTagStart, customBlock.startTagEnd);
const previewTagStart = vueCode.substring(0, customBlock.loc.start.offset).lastIndexOf('<preview');
const previewTag = vueCode.substring(previewTagStart, customBlock.loc.start.offset);
const previewGen = compile(previewTag + '</preview>').ast;
const props: Record<string, string> = {};
for (const previewNode of previewGen.children) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import * as vscode from 'vscode';
import { ref, computed } from '@vue/reactivity';
import * as shared from '@volar/shared';
import * as html from 'vscode-html-languageservice';
import { TextDocument } from 'vscode-languageserver-textdocument';

export const htmlLs = html.getLanguageService();
import { parse, SFCBlock } from '@vue/compiler-sfc';

export function activate(context: vscode.ExtensionContext) {

Expand All @@ -18,7 +15,7 @@ export function activate(context: vscode.ExtensionContext) {
if (!editor) return;

const doc = editor.document;
const descriptor = getDocDescriptor(doc.getText());
const { descriptor } = getDocDescriptor(doc.getText());
const leftBlocks = [
descriptor.scriptSetup,
descriptor.script,
Expand All @@ -33,26 +30,26 @@ export function activate(context: vscode.ExtensionContext) {
await vscode.commands.executeCommand('workbench.action.toggleSplitEditorInGroup');
await foldingBlocks(rightBlocks);

async function foldingBlocks(blocks: shared.SfcBlock[]) {
async function foldingBlocks(blocks: SFCBlock[]) {

const firstBlock = blocks.sort((a, b) => a.startTagEnd - b.startTagEnd)[0];
const firstBlock = blocks.sort((a, b) => a.loc.start.offset - b.loc.start.offset)[0];

const editor = vscode.window.activeTextEditor;
if (!editor) return;

editor.selections = blocks.map(block => new vscode.Selection(doc.positionAt(block.startTagEnd), doc.positionAt(block.startTagEnd)));
editor.selections = blocks.map(block => new vscode.Selection(doc.positionAt(block.loc.start.offset), doc.positionAt(block.loc.start.offset)));

await vscode.commands.executeCommand('editor.unfoldAll');
await vscode.commands.executeCommand('editor.foldLevel1');
editor.revealRange(new vscode.Range(doc.positionAt(firstBlock.startTagEnd), new vscode.Position(editor.document.lineCount, 0)), vscode.TextEditorRevealType.AtTop);
editor.revealRange(new vscode.Range(doc.positionAt(firstBlock.loc.start.offset), new vscode.Position(editor.document.lineCount, 0)), vscode.TextEditorRevealType.AtTop);
}
}
}

function useDocDescriptor() {

const splitDocText = ref('');
const splitDocDescriptor = computed(() => shared.parseSfc(splitDocText.value, htmlLs.parseHTMLDocument(TextDocument.create('', '', 0, splitDocText.value))));
const splitDocDescriptor = computed(() => parse(splitDocText.value, { sourceMap: false, ignoreEmpty: false }));

return getDescriptor;

Expand Down
1 change: 0 additions & 1 deletion packages/code-gen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"directory": "packages/code-gen"
},
"dependencies": {
"@volar/shared": "0.33.2",
"@volar/source-map": "0.33.2"
}
}
Loading