Skip to content

Commit

Permalink
fix: allow arbitrary attributes for pnpm
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Oct 6, 2021
1 parent 0aa1b31 commit 564af29
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 42 deletions.
4 changes: 0 additions & 4 deletions packages/server/src/features/customFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ export function register(
for (const [_, service] of projects.projects.size ? projects.projects : projects.inferredProjects) {
const ls = service.getLanguageServiceDontCreate();
if (!ls) continue;
const globalDoc = ls.__internal__.getGlobalDoc(lsType);
if (globalDoc) {
fs.writeFile(shared.uriToFsPath(globalDoc.uri), globalDoc.getText(), () => { });
}
const localTypes = ls.__internal__.getLocalTypesFiles();
for (const fileName of localTypes.fileNames) {
fs.writeFile(fileName, localTypes.code, () => { });
Expand Down
31 changes: 11 additions & 20 deletions packages/vscode-vue-languageservice/src/languageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type * as vscode from 'vscode-languageserver';
import { TextDocument } from 'vscode-languageserver-textdocument';
import * as shared from '@volar/shared';
import { createSourceFile, SourceFile } from './sourceFile';
import * as globalTypes from './utils/globalTypes';
import * as localTypes from './utils/localTypes';
import * as upath from 'upath';
import type * as ts from 'typescript/lib/tsserverlibrary';
Expand Down Expand Up @@ -157,7 +156,6 @@ export function createLanguageService(
const scriptTsLs = ts2.createLanguageService(ts, scriptTsHost, scriptTsLsRaw);
const localTypesScript = ts.ScriptSnapshot.fromString(localTypes.code);
const localTypesScriptName = '__VLS_types.ts';
const templateLsGlobalDoc = TextDocument.create(shared.fsPathToUri(upath.join(vueHost.getCurrentDirectory(), '__VLS_globals.ts')), 'typescript', 0, globalTypes.code);
const compilerHost = ts.createCompilerHost(vueHost.getCompilationSettings());
const documentContext: html.DocumentContext = {
resolveReference(ref: string, base: string) {
Expand Down Expand Up @@ -278,7 +276,6 @@ export function createLanguageService(
onInitProgress(cb: (p: number) => void) {
initProgressCallback.push(cb);
},
getGlobalDoc,
getLocalTypesFiles: () => {
const fileNames = getLocalTypesFiles();
const code = localTypes.code;
Expand All @@ -298,9 +295,6 @@ export function createLanguageService(
function getLocalTypesFiles() {
return sourceFiles.getDirs().map(dir => upath.join(dir, localTypesScriptName));
}
function getGlobalDoc(lsType: 'script' | 'template') {
return lsType === 'template' ? templateLsGlobalDoc : undefined;
}
function createTsPluginProxy() {

// ts plugin proxy
Expand Down Expand Up @@ -557,9 +551,6 @@ export function createLanguageService(
function getScriptFileNames() {
const tsFileNames = getLocalTypesFiles();

const globalDoc = getGlobalDoc(lsType);
if (globalDoc) tsFileNames.push(shared.uriToFsPath(globalDoc.uri));

for (const [tsUri] of sourceFiles.getTsDocuments(lsType)) {
tsFileNames.push(shared.uriToFsPath(tsUri)); // virtual .ts
}
Expand All @@ -575,9 +566,6 @@ export function createLanguageService(
}
function getScriptVersion(fileName: string) {
const uri = shared.fsPathToUri(fileName);
if (uri === templateLsGlobalDoc.uri) {
return templateLsGlobalDoc.version.toString();
}
if (upath.basename(fileName) === localTypesScriptName) {
return '0';
}
Expand All @@ -593,16 +581,11 @@ export function createLanguageService(
if (cache && cache[0] === version) {
return cache[1];
}
const uri = shared.fsPathToUri(fileName);
if (uri === templateLsGlobalDoc.uri) {
const text = templateLsGlobalDoc.getText();
const snapshot = ts.ScriptSnapshot.fromString(text);
scriptSnapshots.set(fileName, [version, snapshot]);
return snapshot;
}
if (upath.basename(fileName) === localTypesScriptName) {
const basename = upath.basename(fileName);
if (basename === localTypesScriptName) {
return localTypesScript;
}
const uri = shared.fsPathToUri(fileName);
const doc = sourceFiles.getTsDocuments(lsType).get(uri);
if (doc) {
const text = doc.getText();
Expand All @@ -612,6 +595,14 @@ export function createLanguageService(
}
let tsScript = vueHost.getScriptSnapshot(fileName);
if (tsScript) {
if (lsType === 'template' && basename === 'runtime-dom.d.ts') {
// allow arbitrary attributes
const extraTypes = [
'interface AriaAttributes extends Record<string, unknown> { }',
'declare global { namespace JSX { interface IntrinsicAttributes extends Record<string, unknown> {} } }',
];
tsScript = ts.ScriptSnapshot.fromString(tsScript.getText(0, tsScript.getLength()) + '\n' + extraTypes.join('\n'));
}
scriptSnapshots.set(fileName, [version, tsScript]);
return tsScript;
}
Expand Down
14 changes: 0 additions & 14 deletions packages/vscode-vue-languageservice/src/utils/globalTypes.ts

This file was deleted.

4 changes: 0 additions & 4 deletions packages/vscode-vue-languageservice/src/utils/localTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ export type ExtractComponentProps<T> =
T extends new (...args: any) => { $props?: infer P1 } ? P1
: T extends FunctionalComponent<infer P2> ? P2
: T
export type ExtractCompleteComponentProps<T> =
T extends new (...args: any) => { $props?: infer P1 } ? P1 & Omit<GlobalAttrs, keyof P1> & Record<string, unknown>
: T extends FunctionalComponent<infer P2> ? P2 & JSX.IntrinsicAttributes & Record<string, unknown>
: T & Omit<GlobalAttrs, keyof T> & Record<string, unknown>
export type ExtractRawComponents<T> = { [K in keyof T]: ExtractRawComponent<T[K]> };
export type ExtractRawComponent<T> = T extends { raw: infer C } ? C : T;
Expand Down

0 comments on commit 564af29

Please sign in to comment.