Skip to content

Commit 564af29

Browse files
committed
fix: allow arbitrary attributes for pnpm
1 parent 0aa1b31 commit 564af29

File tree

4 files changed

+11
-42
lines changed

4 files changed

+11
-42
lines changed

packages/server/src/features/customFeatures.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ export function register(
2828
for (const [_, service] of projects.projects.size ? projects.projects : projects.inferredProjects) {
2929
const ls = service.getLanguageServiceDontCreate();
3030
if (!ls) continue;
31-
const globalDoc = ls.__internal__.getGlobalDoc(lsType);
32-
if (globalDoc) {
33-
fs.writeFile(shared.uriToFsPath(globalDoc.uri), globalDoc.getText(), () => { });
34-
}
3531
const localTypes = ls.__internal__.getLocalTypesFiles();
3632
for (const fileName of localTypes.fileNames) {
3733
fs.writeFile(fileName, localTypes.code, () => { });

packages/vscode-vue-languageservice/src/languageService.ts

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type * as vscode from 'vscode-languageserver';
22
import { TextDocument } from 'vscode-languageserver-textdocument';
33
import * as shared from '@volar/shared';
44
import { createSourceFile, SourceFile } from './sourceFile';
5-
import * as globalTypes from './utils/globalTypes';
65
import * as localTypes from './utils/localTypes';
76
import * as upath from 'upath';
87
import type * as ts from 'typescript/lib/tsserverlibrary';
@@ -157,7 +156,6 @@ export function createLanguageService(
157156
const scriptTsLs = ts2.createLanguageService(ts, scriptTsHost, scriptTsLsRaw);
158157
const localTypesScript = ts.ScriptSnapshot.fromString(localTypes.code);
159158
const localTypesScriptName = '__VLS_types.ts';
160-
const templateLsGlobalDoc = TextDocument.create(shared.fsPathToUri(upath.join(vueHost.getCurrentDirectory(), '__VLS_globals.ts')), 'typescript', 0, globalTypes.code);
161159
const compilerHost = ts.createCompilerHost(vueHost.getCompilationSettings());
162160
const documentContext: html.DocumentContext = {
163161
resolveReference(ref: string, base: string) {
@@ -278,7 +276,6 @@ export function createLanguageService(
278276
onInitProgress(cb: (p: number) => void) {
279277
initProgressCallback.push(cb);
280278
},
281-
getGlobalDoc,
282279
getLocalTypesFiles: () => {
283280
const fileNames = getLocalTypesFiles();
284281
const code = localTypes.code;
@@ -298,9 +295,6 @@ export function createLanguageService(
298295
function getLocalTypesFiles() {
299296
return sourceFiles.getDirs().map(dir => upath.join(dir, localTypesScriptName));
300297
}
301-
function getGlobalDoc(lsType: 'script' | 'template') {
302-
return lsType === 'template' ? templateLsGlobalDoc : undefined;
303-
}
304298
function createTsPluginProxy() {
305299

306300
// ts plugin proxy
@@ -557,9 +551,6 @@ export function createLanguageService(
557551
function getScriptFileNames() {
558552
const tsFileNames = getLocalTypesFiles();
559553

560-
const globalDoc = getGlobalDoc(lsType);
561-
if (globalDoc) tsFileNames.push(shared.uriToFsPath(globalDoc.uri));
562-
563554
for (const [tsUri] of sourceFiles.getTsDocuments(lsType)) {
564555
tsFileNames.push(shared.uriToFsPath(tsUri)); // virtual .ts
565556
}
@@ -575,9 +566,6 @@ export function createLanguageService(
575566
}
576567
function getScriptVersion(fileName: string) {
577568
const uri = shared.fsPathToUri(fileName);
578-
if (uri === templateLsGlobalDoc.uri) {
579-
return templateLsGlobalDoc.version.toString();
580-
}
581569
if (upath.basename(fileName) === localTypesScriptName) {
582570
return '0';
583571
}
@@ -593,16 +581,11 @@ export function createLanguageService(
593581
if (cache && cache[0] === version) {
594582
return cache[1];
595583
}
596-
const uri = shared.fsPathToUri(fileName);
597-
if (uri === templateLsGlobalDoc.uri) {
598-
const text = templateLsGlobalDoc.getText();
599-
const snapshot = ts.ScriptSnapshot.fromString(text);
600-
scriptSnapshots.set(fileName, [version, snapshot]);
601-
return snapshot;
602-
}
603-
if (upath.basename(fileName) === localTypesScriptName) {
584+
const basename = upath.basename(fileName);
585+
if (basename === localTypesScriptName) {
604586
return localTypesScript;
605587
}
588+
const uri = shared.fsPathToUri(fileName);
606589
const doc = sourceFiles.getTsDocuments(lsType).get(uri);
607590
if (doc) {
608591
const text = doc.getText();
@@ -612,6 +595,14 @@ export function createLanguageService(
612595
}
613596
let tsScript = vueHost.getScriptSnapshot(fileName);
614597
if (tsScript) {
598+
if (lsType === 'template' && basename === 'runtime-dom.d.ts') {
599+
// allow arbitrary attributes
600+
const extraTypes = [
601+
'interface AriaAttributes extends Record<string, unknown> { }',
602+
'declare global { namespace JSX { interface IntrinsicAttributes extends Record<string, unknown> {} } }',
603+
];
604+
tsScript = ts.ScriptSnapshot.fromString(tsScript.getText(0, tsScript.getLength()) + '\n' + extraTypes.join('\n'));
605+
}
615606
scriptSnapshots.set(fileName, [version, tsScript]);
616607
return tsScript;
617608
}

packages/vscode-vue-languageservice/src/utils/globalTypes.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

packages/vscode-vue-languageservice/src/utils/localTypes.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,6 @@ export type ExtractComponentProps<T> =
8686
T extends new (...args: any) => { $props?: infer P1 } ? P1
8787
: T extends FunctionalComponent<infer P2> ? P2
8888
: T
89-
export type ExtractCompleteComponentProps<T> =
90-
T extends new (...args: any) => { $props?: infer P1 } ? P1 & Omit<GlobalAttrs, keyof P1> & Record<string, unknown>
91-
: T extends FunctionalComponent<infer P2> ? P2 & JSX.IntrinsicAttributes & Record<string, unknown>
92-
: T & Omit<GlobalAttrs, keyof T> & Record<string, unknown>
9389
9490
export type ExtractRawComponents<T> = { [K in keyof T]: ExtractRawComponent<T[K]> };
9591
export type ExtractRawComponent<T> = T extends { raw: infer C } ? C : T;

0 commit comments

Comments
 (0)