@@ -18,6 +18,7 @@ import { get } from './configRenames';
1818import * as Annotator from './annotator' ;
1919import { LuaRocksManager } from './luarocks/LuaRocksManager' ;
2020import { LuaRocksTreeProvider , PackageTreeItem } from './luarocks/LuaRocksTreeProvider' ;
21+ import { EmmyrcSchemaContentProvider } from './emmyrcSchemaContentProvider' ;
2122interface DebuggerConfig {
2223 readonly type : string ;
2324 readonly provider : vscode . DebugConfigurationProvider ;
@@ -558,57 +559,4 @@ async function checkLuaRocksInstallation(): Promise<void> {
558559 vscode . env . openExternal ( vscode . Uri . parse ( 'https://luarocks.org/#quick-start' ) ) ;
559560 }
560561 }
561- }
562-
563-
564-
565- /**
566- * 提供`.emmyrc.json`的 i18n
567- */
568- class EmmyrcSchemaContentProvider implements vscode . TextDocumentContentProvider {
569- private readonly schemaBaseDir : string ;
570-
571- constructor ( context : vscode . ExtensionContext ) {
572- this . schemaBaseDir = path . join ( context . extensionPath , 'syntaxes' ) ;
573- }
574-
575- async provideTextDocumentContent ( uri : vscode . Uri ) : Promise < string > {
576- const schemaIdentifier = path . posix . basename ( uri . path ) ;
577- const locale = vscode . env . language ;
578- let schemaFileName : string ;
579-
580- if ( schemaIdentifier === 'emmyrc' ) {
581- switch ( locale ) {
582- case 'zh-cn' :
583- case 'zh-CN' :
584- case 'zh' :
585- schemaFileName = 'schema.zh-cn.json' ;
586- break ;
587- case 'en' :
588- case 'en-US' :
589- case 'en-GB' :
590- default :
591- schemaFileName = 'schema.json' ;
592- break ;
593- }
594- } else {
595- return '' ;
596- }
597-
598- // 检查schema文件是否存在, 如果不存在则使用默认的
599- let schemaFilePath = path . join ( this . schemaBaseDir , schemaFileName ) ;
600- if ( ! fs . existsSync ( schemaFilePath ) ) {
601- schemaFilePath = path . join ( this . schemaBaseDir , 'schema.json' ) ;
602- }
603-
604- try {
605- return await fs . promises . readFile ( schemaFilePath , 'utf8' ) ;
606- } catch ( error : any ) {
607- return JSON . stringify ( {
608- "$schema" : "https://json-schema.org/draft/2020-12/schema#" ,
609- "title" : "Error Loading Schema" ,
610- "description" : `Could not load schema: ${ schemaFileName } . Error: ${ error . message } .`
611- } ) ;
612- }
613- }
614562}
0 commit comments