Skip to content

Commit e0ff00c

Browse files
committed
fixup! refactor order in vscode.ts
1 parent a2597a2 commit e0ff00c

File tree

1 file changed

+43
-40
lines changed

1 file changed

+43
-40
lines changed

src/browser/pages/vscode.ts

+43-40
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import { getOptions, Options } from "../../common/util"
22
import "../register"
33

4-
const options = getOptions()
5-
6-
// TODO: Add proper types.
7-
/* eslint-disable @typescript-eslint/no-explicit-any */
4+
// TODO@jsjoeio: Add proper types.
5+
type FixMeLater = any
86

97
// NOTE@jsjoeio
108
// This lives here ../../../lib/vscode/src/vs/base/common/platform.ts#L106
@@ -19,7 +17,7 @@ type NlsConfiguration = {
1917
_resolvedLanguagePackCoreLocation?: string
2018
_corruptedFile?: string
2119
_languagePackSupport?: boolean
22-
loadBundle?: any
20+
loadBundle?: FixMeLater
2321
}
2422

2523
/**
@@ -114,40 +112,9 @@ export function getLoader({ origin, nlsConfig, options }: GetLoaderParams) {
114112
return loader
115113
}
116114

117-
try {
118-
const nlsConfig = getNlsConfiguration(document)
119-
if (nlsConfig._resolvedLanguagePackCoreLocation) {
120-
const bundles = Object.create(null)
121-
nlsConfig.loadBundle = (bundle: any, _language: any, cb: any): void => {
122-
const result = bundles[bundle]
123-
if (result) {
124-
return cb(undefined, result)
125-
}
126-
// FIXME: Only works if path separators are /.
127-
const path = nlsConfig._resolvedLanguagePackCoreLocation + "/" + bundle.replace(/\//g, "!") + ".nls.json"
128-
fetch(`${options.base}/vscode/resource/?path=${encodeURIComponent(path)}`)
129-
.then((response) => response.json())
130-
.then((json) => {
131-
bundles[bundle] = json
132-
cb(undefined, json)
133-
})
134-
.catch(cb)
135-
}
136-
}
137-
// TODO@jsjoeio
138-
// I'm not sure how to properly type cast this
139-
// This might be our best bet
140-
// Source: https://stackoverflow.com/a/30740935
141-
type FixMeLater = any
142-
;(self.require as FixMeLater) = getLoader({
143-
nlsConfig,
144-
options,
145-
origin: window.location.origin,
146-
})
147-
} catch (error) {
148-
console.error(error)
149-
}
150-
115+
/**
116+
* Sets the body background color to match the theme.
117+
*/
151118
export function setBodyBackgroundToThemeBackgroundColor(document: Document, localStorage: Storage) {
152119
const errorMsgPrefix = "[vscode]"
153120

@@ -204,8 +171,44 @@ export function setBodyBackgroundToThemeBackgroundColor(document: Document, loca
204171
}
205172

206173
try {
174+
const options = getOptions()
175+
const nlsConfig = getNlsConfiguration(document)
176+
177+
if (nlsConfig._resolvedLanguagePackCoreLocation) {
178+
const bundles = Object.create(null)
179+
180+
nlsConfig.loadBundle = (bundle: FixMeLater, _language: FixMeLater, cb: FixMeLater): void => {
181+
const result = bundles[bundle]
182+
if (result) {
183+
return cb(undefined, result)
184+
}
185+
// FIXME: Only works if path separators are /.
186+
const path = nlsConfig._resolvedLanguagePackCoreLocation + "/" + bundle.replace(/\//g, "!") + ".nls.json"
187+
fetch(`${options.base}/vscode/resource/?path=${encodeURIComponent(path)}`)
188+
.then((response) => response.json())
189+
.then((json) => {
190+
bundles[bundle] = json
191+
cb(undefined, json)
192+
})
193+
.catch(cb)
194+
}
195+
}
196+
197+
const loader = getLoader({
198+
nlsConfig,
199+
options,
200+
origin: window.location.origin,
201+
})
202+
203+
// TODO@jsjoeio
204+
// I'm not sure how to properly type cast this
205+
// This might be our best bet
206+
// Source: https://stackoverflow.com/a/30740935
207+
// This object on self.require is what configures the loader
208+
// and tells it how to load files that get imported.
209+
;(self.require as FixMeLater) = loader
210+
207211
setBodyBackgroundToThemeBackgroundColor(document, localStorage)
208212
} catch (error) {
209-
console.error("Something went wrong setting the body background to the theme background color.")
210213
console.error(error)
211214
}

0 commit comments

Comments
 (0)