11import { URI } from 'vscode-uri' ;
2- import { Connection , WorkspaceFolder } from 'vscode-languageserver' ;
2+ import { Connection , RequestType , WorkspaceFolder } from 'vscode-languageserver' ;
33import { xhr , XHRResponse , getErrorStatusDescription } from 'request-light' ;
44import * as URL from 'url' ;
55import { CustomSchemaContentRequest , VSCodeContentRequest } from '../../requestTypes' ;
66import { isRelativePath , relativeToAbsolutePath } from '../utils/paths' ;
77import { WorkspaceContextService } from '../yamlLanguageService' ;
8+ import { dirname , join } from 'path' ;
89
910export interface FileSystem {
1011 readFile ( fsPath : string , encoding ?: string ) : Promise < string > ;
1112}
1213
14+ // eslint-disable-next-line @typescript-eslint/no-namespace
15+ namespace FSReadUri {
16+ export const type : RequestType < string , string , unknown > = new RequestType ( 'fs/readUri' ) ;
17+ }
18+
1319/**
1420 * Handles schema content requests given the schema URI
1521 * @param uri can be a local file, vscode request, http(s) request or a custom request
@@ -29,7 +35,18 @@ export const schemaRequestHandler = (
2935 // If the requested schema URI is a relative file path
3036 // Convert it into a proper absolute path URI
3137 if ( isRelativePath ( uri ) ) {
32- uri = relativeToAbsolutePath ( workspaceFolders , workspaceRoot , uri ) ;
38+ if ( workspaceFolders . length === 1 ) {
39+ const wsUri = URI . parse ( workspaceFolders [ 0 ] . uri ) ;
40+ const wsDirname = dirname ( wsUri . path ) ;
41+ connection . window . showInformationMessage ( `wsDirname: ${ wsDirname } ` ) ;
42+ const modifiedUri = wsUri . with ( { path : join ( wsDirname , uri ) } ) ;
43+ return connection . sendRequest ( FSReadUri . type , modifiedUri . toString ( ) ) . catch ( ( e ) => {
44+ connection . window . showErrorMessage ( `failed to get content of '${ modifiedUri } ': ${ e } ` ) ;
45+ throw e ;
46+ } ) ;
47+ } else {
48+ uri = relativeToAbsolutePath ( workspaceFolders , workspaceRoot , uri ) ;
49+ }
3350 }
3451
3552 let scheme = URI . parse ( uri ) . scheme . toLowerCase ( ) ;
0 commit comments