@@ -2,7 +2,6 @@ import type * as vscode from 'vscode-languageserver';
2
2
import { TextDocument } from 'vscode-languageserver-textdocument' ;
3
3
import * as shared from '@volar/shared' ;
4
4
import { createSourceFile , SourceFile } from './sourceFile' ;
5
- import * as globalTypes from './utils/globalTypes' ;
6
5
import * as localTypes from './utils/localTypes' ;
7
6
import * as upath from 'upath' ;
8
7
import type * as ts from 'typescript/lib/tsserverlibrary' ;
@@ -157,7 +156,6 @@ export function createLanguageService(
157
156
const scriptTsLs = ts2 . createLanguageService ( ts , scriptTsHost , scriptTsLsRaw ) ;
158
157
const localTypesScript = ts . ScriptSnapshot . fromString ( localTypes . code ) ;
159
158
const localTypesScriptName = '__VLS_types.ts' ;
160
- const templateLsGlobalDoc = TextDocument . create ( shared . fsPathToUri ( upath . join ( vueHost . getCurrentDirectory ( ) , '__VLS_globals.ts' ) ) , 'typescript' , 0 , globalTypes . code ) ;
161
159
const compilerHost = ts . createCompilerHost ( vueHost . getCompilationSettings ( ) ) ;
162
160
const documentContext : html . DocumentContext = {
163
161
resolveReference ( ref : string , base : string ) {
@@ -278,7 +276,6 @@ export function createLanguageService(
278
276
onInitProgress ( cb : ( p : number ) => void ) {
279
277
initProgressCallback . push ( cb ) ;
280
278
} ,
281
- getGlobalDoc,
282
279
getLocalTypesFiles : ( ) => {
283
280
const fileNames = getLocalTypesFiles ( ) ;
284
281
const code = localTypes . code ;
@@ -298,9 +295,6 @@ export function createLanguageService(
298
295
function getLocalTypesFiles ( ) {
299
296
return sourceFiles . getDirs ( ) . map ( dir => upath . join ( dir , localTypesScriptName ) ) ;
300
297
}
301
- function getGlobalDoc ( lsType : 'script' | 'template' ) {
302
- return lsType === 'template' ? templateLsGlobalDoc : undefined ;
303
- }
304
298
function createTsPluginProxy ( ) {
305
299
306
300
// ts plugin proxy
@@ -557,9 +551,6 @@ export function createLanguageService(
557
551
function getScriptFileNames ( ) {
558
552
const tsFileNames = getLocalTypesFiles ( ) ;
559
553
560
- const globalDoc = getGlobalDoc ( lsType ) ;
561
- if ( globalDoc ) tsFileNames . push ( shared . uriToFsPath ( globalDoc . uri ) ) ;
562
-
563
554
for ( const [ tsUri ] of sourceFiles . getTsDocuments ( lsType ) ) {
564
555
tsFileNames . push ( shared . uriToFsPath ( tsUri ) ) ; // virtual .ts
565
556
}
@@ -575,9 +566,6 @@ export function createLanguageService(
575
566
}
576
567
function getScriptVersion ( fileName : string ) {
577
568
const uri = shared . fsPathToUri ( fileName ) ;
578
- if ( uri === templateLsGlobalDoc . uri ) {
579
- return templateLsGlobalDoc . version . toString ( ) ;
580
- }
581
569
if ( upath . basename ( fileName ) === localTypesScriptName ) {
582
570
return '0' ;
583
571
}
@@ -593,16 +581,11 @@ export function createLanguageService(
593
581
if ( cache && cache [ 0 ] === version ) {
594
582
return cache [ 1 ] ;
595
583
}
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 ) {
604
586
return localTypesScript ;
605
587
}
588
+ const uri = shared . fsPathToUri ( fileName ) ;
606
589
const doc = sourceFiles . getTsDocuments ( lsType ) . get ( uri ) ;
607
590
if ( doc ) {
608
591
const text = doc . getText ( ) ;
@@ -612,6 +595,14 @@ export function createLanguageService(
612
595
}
613
596
let tsScript = vueHost . getScriptSnapshot ( fileName ) ;
614
597
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
+ }
615
606
scriptSnapshots . set ( fileName , [ version , tsScript ] ) ;
616
607
return tsScript ;
617
608
}
0 commit comments