Skip to content

Commit

Permalink
fix: add typescript worker file system provider
Browse files Browse the repository at this point in the history
  • Loading branch information
Loïc Mangeonjean committed Jun 5, 2023
1 parent 7ba00d6 commit 625e3d2
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/service-override/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { DisposableStore, IDisposable, Disposable } from 'vs/base/common/lifecyc
import { joinPath } from 'vs/base/common/resources'
import { Emitter, Event } from 'vs/base/common/event'
import { HTMLFileSystemProvider } from 'vs/platform/files/browser/htmlFileSystemProvider'
import * as monaco from 'monaco-editor'
import 'vs/workbench/contrib/files/browser/files.contribution'

class File implements IStat {
Expand Down Expand Up @@ -84,8 +85,7 @@ abstract class SimpleTextFileSystemProvider implements IFileSystemProviderWithFi
// Do nothing
}

async readdir (directory: URI): Promise<[string, FileType][]> {
console.debug('Not implemented: readdir', directory)
async readdir (_directory: monaco.Uri): Promise<[string, FileType][]> {
return []
}

Expand All @@ -100,6 +100,20 @@ abstract class SimpleTextFileSystemProvider implements IFileSystemProviderWithFi
onDidWatchError = Event.None
}

class TypescriptWorkerFileSystemProvider extends SimpleTextFileSystemProvider {
protected async getFileContent (resource: URI): Promise<string | undefined> {
const typescript = monaco.languages.typescript
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (typescript == null) {
return undefined
}
const path = resource.path.slice(1)
return typescript.typescriptDefaults.getExtraLibs()[path]?.content ?? typescript.javascriptDefaults.getExtraLibs()[path]?.content
}

protected async setFileContent (): Promise<void> {}
}

class ExtensionFileSystemProviderWithFileReadWriteCapability implements IFileSystemProviderWithFileReadWriteCapability {
capabilities = FileSystemProviderCapabilities.FileReadWrite | FileSystemProviderCapabilities.PathCaseSensitive | FileSystemProviderCapabilities.Readonly

Expand Down Expand Up @@ -312,6 +326,8 @@ export function registerFileSystemOverlay (provider: IFileSystemProviderWithFile
return fileSystemProvider.register(provider)
}

registerFileSystemOverlay(new TypescriptWorkerFileSystemProvider())

export {
IFileSystemProviderWithFileReadWriteCapability,
FileSystemProviderCapabilities,
Expand Down

0 comments on commit 625e3d2

Please sign in to comment.