Skip to main content

Module UriComponents

Module UriComponents 

Source
Expand description

Shared UriComponents emitter. Every handler that returns a URI to the renderer must route through this module so the $mid: 1 marshalling marker is never forgotten (without it VS Code’s IPC reviver skips the field and uri.with is not a function cascades through the sidebar).

§UriComponents - VS Code marshalling helpers

Centralised builders for VS Code UriComponents payloads. The renderer’s reviver (_transformIncomingURIs in uriIpc.ts) walks every response object and only calls URI.revive() on nested objects tagged with $mid === MarshalledId.Uri (= 1). An untagged UriComponents reaches callers as a plain bag - uri.with is not a function, uri.fsPath undefined - and the sidebar / icon loader / joinPath chain silently breaks.

Layout (one export per file, file name = identity):

  • MID_URI::VALUE - the magic marshalling constant.
  • StampMidUri::Fn - tag a Value::Object with $mid: 1.
  • FromFilePath::Fn - file://-scheme builder from an absolute path.
  • FromUrl::Fn - generic-scheme builder from a URL string.
  • Normalize::Fn - accept string / object / missing and return a tagged URI bag.

Modules§

FromFilePath
Build a file:// UriComponents from an absolute filesystem path. Path is emitted verbatim - no percent-encoding, no normalisation - mirroring what VS Code’s URI.file(…) readers expect.
FromUrl
Build a UriComponents from a fully-formed URL string. Handles file:// (authority-optional) and any other scheme generically (scheme:path + optional //authority). Fragment / query are split off verbatim so downstream URI.revive() reconstructs the same URL. Strings that don’t parse as URLs fall back to { scheme:"file", path:<input> } - a defensive shape the workbench tolerates for unknown-location placeholders.
MID_URI
MarshalledId.Uri constant from VS Code’s src/vs/base/common/marshallingIds.ts. The renderer’s URI reviver (_transformIncomingURIs in uriIpc.ts) keys off this exact value to decide whether to call URI.revive(). If VS Code ever renumbers the enum, this constant must move in lockstep.
Normalize
Normalise an extensionLocation (or any similar) field that arrives as either a URL string, a pre-built UriComponents object (possibly already tagged), or is missing / null. The output is always a tagged object with the five URI fields.
StampMidUri
Insert $mid: 1 into a UriComponents object if it isn’t already tagged. Non-object values pass through unchanged so call sites can pipe any serde_json::Value through without branching first.