Skip to content

Commit

Permalink
🐛 Fix special URL parsing, add missing vanilla files to cache (#1139)
Browse files Browse the repository at this point in the history
  • Loading branch information
SPGoding authored May 14, 2024
1 parent c17cbdb commit 43f5403
Show file tree
Hide file tree
Showing 13 changed files with 214 additions and 58 deletions.
109 changes: 98 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
"globby": "^11.0.4",
"pako": "^2.0.4",
"rfdc": "^1.3.0",
"vscode-languageserver-textdocument": "^1.0.4"
"vscode-languageserver-textdocument": "^1.0.4",
"whatwg-url": "^14.0.0"
},
"devDependencies": {
"@types/decompress": "^4.2.3",
"@types/follow-redirects": "^1.14.1",
"@types/pako": "^2.0.0"
"@types/pako": "^2.0.0",
"@types/whatwg-url": "^11.0.4"
},
"publishConfig": {
"access": "public"
Expand Down
10 changes: 8 additions & 2 deletions packages/core/src/common/externals/NodeJsExternals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,13 @@ Object.freeze(NodeJsExternals)
* @returns A {@link fs.PathLike}.
*/
function toFsPathLike(path: FsLocation): fs.PathLike {
if (path instanceof Uri) {
// Convert WHATWG URL to string so that it will be converted
// to Node.js URL by the next if-block.
path = path.toString()
}
if (typeof path === 'string' && path.startsWith('file:')) {
return new Uri(path)
return new url.URL(path)
}
return path
}
Expand All @@ -155,7 +160,8 @@ function toPath(path: FsLocation): string {
return uriToPath(path)
}

const uriToPath = (uri: string | Uri) => url.fileURLToPath(uri)
const uriToPath = (uri: string | Uri) =>
url.fileURLToPath(uri instanceof Uri ? new url.URL(uri.toString()) : uri)
const uriFromPath = (path: string) => url.pathToFileURL(path).toString()

class ChokidarWatcherWrapper extends EventEmitter implements FsWatcher {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/common/externals/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export interface ExternalFileSystem {
}

/**
* A file file URI string or a URI object.
* A file URI string or a URI object.
*/
export type FsLocation = string | Uri

Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/common/util.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import externalBinarySearch from 'binary-search'
import rfdc from 'rfdc'
import { URL } from 'whatwg-url'
import type { AstNode } from '../node/index.js'
import type { ProcessorContext } from '../service/index.js'
import type { Externals } from './externals/index.js'
import type { DeepReadonly } from './ReadonlyProxy.js'

// Spyglass uses the URL class provided by the
// [spec](https://url.spec.whatwg.org/)-compliant `whatwg-url` package instead
// of the broken one shipped with browsers that do not parse non-special scheme
// URLs with hosts properly.
//
// * [Chromium bug](https://issues.chromium.org/issues/40587286)
// * [FireFox bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1374505)
//
// We use the name "URI" instead of "URL" when possible, since it is what
// LSP has chosen to use for the string that uniquely identifies a file.
export const Uri = URL
export type Uri = URL

Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/service/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,10 @@ export namespace SymbolLinterConfig {
export const VanillaConfig: Config = {
env: {
dataSource: 'GitHub',
dependencies: ['@vanilla-mcdoc'],
dependencies: [
'@vanilla-datapack',
'@vanilla-mcdoc',
],
feature: {
codeActions: true,
colors: true,
Expand Down
Loading

0 comments on commit 43f5403

Please sign in to comment.