-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: override fetch to use file service if possible
- Loading branch information
Loïc Mangeonjean
committed
Jun 16, 2023
1 parent
b521f69
commit 0bc6736
Showing
4 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { IFileService } from 'vs/platform/files/common/files' | ||
import { StandaloneServices } from 'vs/editor/standalone/browser/standaloneServices' | ||
import { URI } from 'vs/base/common/uri' | ||
import { unsupported } from './tools' | ||
|
||
const fetch: typeof window.fetch = async (input: RequestInfo | URL, init?: RequestInit) => { | ||
if (typeof input === 'string') { | ||
const uri = URI.parse(input) | ||
const fileService = StandaloneServices.get(IFileService) | ||
if (fileService.hasProvider(uri)) { | ||
const response: Response = { | ||
get headers () { return unsupported() }, | ||
ok: true, | ||
redirected: false, | ||
status: 200, | ||
statusText: 'Ok', | ||
type: 'basic', | ||
url: input, | ||
clone: unsupported, | ||
get body () { return unsupported() }, | ||
bodyUsed: false, | ||
arrayBuffer: unsupported, | ||
blob: unsupported, | ||
formData: unsupported, | ||
json: unsupported, | ||
text: async function (): Promise<string> { | ||
const content = await fileService.readFile(URI.parse(input)) | ||
return content.value.toString() | ||
} | ||
} | ||
return response | ||
} | ||
} | ||
return window.fetch(input, init) | ||
} | ||
|
||
export default fetch |