Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
49 changes: 23 additions & 26 deletions packages/language-core/lib/virtualFile/vueFile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { VirtualCode } from '@volar/language-core';
import type { CodeInformation, Mapping, VirtualCode } from '@volar/language-core';
import { computed, signal } from 'alien-signals';
import type * as ts from 'typescript';
import { allCodeFeatures } from '../plugins';
Expand All @@ -8,38 +8,23 @@ import { computedSfc } from './computedSfc';
import { computedVueSfc } from './computedVueSfc';

export class VueVirtualCode implements VirtualCode {
// sources
readonly id = 'main';
readonly sfc: ReturnType<typeof computedSfc>;

id = 'main';

private _snapshot = signal<ts.IScriptSnapshot>(undefined!);

// computeds

private _vueSfc = computedVueSfc(this.plugins, this.fileName, this.languageId, this._snapshot);
private _sfc = computedSfc(this.ts, this.plugins, this.fileName, this._snapshot, this._vueSfc);
private _embeddedCodes = computedEmbeddedCodes(this.plugins, this.fileName, this._sfc);
private _mappings = computed(() => {
const snapshot = this._snapshot();
return [{
sourceOffsets: [0],
generatedOffsets: [0],
lengths: [snapshot.getLength()],
data: allCodeFeatures,
}];
});

// others
private _snapshot: {
(): ts.IScriptSnapshot;
(value: ts.IScriptSnapshot): void;
};
private _vueSfc: ReturnType<typeof computedVueSfc>;
private _embeddedCodes: ReturnType<typeof computedEmbeddedCodes>;
private _mappings: () => Mapping<CodeInformation>[];

get snapshot() {
return this._snapshot();
}
get vueSfc() {
return this._vueSfc();
}
get sfc() {
return this._sfc;
}
get embeddedCodes() {
return this._embeddedCodes();
}
Expand All @@ -55,7 +40,19 @@ export class VueVirtualCode implements VirtualCode {
public plugins: VueLanguagePluginReturn[],
public ts: typeof import('typescript'),
) {
this._snapshot(initSnapshot);
this._snapshot = signal(initSnapshot);
this._vueSfc = computedVueSfc(this.plugins, this.fileName, this.languageId, this._snapshot);
this.sfc = computedSfc(this.ts, this.plugins, this.fileName, this._snapshot, this._vueSfc);
this._embeddedCodes = computedEmbeddedCodes(this.plugins, this.fileName, this.sfc);
this._mappings = computed(() => {
const snapshot = this._snapshot();
return [{
sourceOffsets: [0],
generatedOffsets: [0],
lengths: [snapshot.getLength()],
data: allCodeFeatures,
}];
});
}

update(newSnapshot: ts.IScriptSnapshot) {
Expand Down
4 changes: 2 additions & 2 deletions packages/typescript-plugin/lib/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ function getCompletionEntryDetails<T>(
const { fileName } = args[6].__isAutoImport;
const sourceScript = language.scripts.get(fileName);
if (sourceScript?.generated?.root instanceof VueVirtualCode) {
const sfc = sourceScript.generated.root.vueSfc;
if (!sfc?.descriptor.script && !sfc?.descriptor.scriptSetup) {
const { vueSfc } = sourceScript.generated.root;
if (!vueSfc?.descriptor.script && !vueSfc?.descriptor.scriptSetup) {
for (const codeAction of details?.codeActions ?? []) {
for (const change of codeAction.changes) {
for (const textChange of change.textChanges) {
Expand Down
Loading