docpath

package
v0.1.20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2026 License: BSD-3-Clause, MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DocumentURI

type DocumentURI string

A DocumentURI is the URI of a client editor document.

According to the LSP specification:

Care should be taken to handle encoding in URIs. For
example, some clients (such as VS Code) may encode colons
in drive letters while others do not. The URIs below are
both valid, but clients and servers should be consistent
with the form they use themselves to ensure the other party
doesn’t interpret them as distinct URIs. Clients and
servers should not assume that each other are encoding the
same way (for example a client encoding colons in drive
letters cannot assume server responses will have encoded
colons). The same applies to casing of drive letters - one
party should not assume the other party will return paths
with drive letters cased the same as it.

file:///c:/project/readme.md
file:///C%3A/project/readme.md

This is done during JSON unmarshalling; see DocumentURI.UnmarshalText for details.

func ParseDocumentURI

func ParseDocumentURI(s string) (DocumentURI, error)

ParseDocumentURI interprets a string as a DocumentURI, applying VS Code workarounds; see DocumentURI.UnmarshalText for details. If "s" is a file name, use URIFromPath instead.

func URIFromPath

func URIFromPath(path string) DocumentURI

URIFromPath returns DocumentURI for the supplied file path. Given "", it returns "".

func (DocumentURI) Base

func (uri DocumentURI) Base() string

Base returns the base name of the file path of the given URI.

func (DocumentURI) Clean

func (uri DocumentURI) Clean() DocumentURI

Clean returns the cleaned uri by triggering filepath.Clean underlying.

func (DocumentURI) Dir

func (uri DocumentURI) Dir() DocumentURI

Dir returns the URI for the directory containing the receiver.

func (DocumentURI) DirPath

func (uri DocumentURI) DirPath() string

DirPath returns the file path to the directory containing this URI, which must be a file URI.

func (DocumentURI) Path

func (uri DocumentURI) Path() string

Path returns the file path for the given URI.

DocumentURI("").Path() returns the empty string.

Path panics if called on a URI that is not a valid filename.

func (*DocumentURI) UnmarshalText

func (uri *DocumentURI) UnmarshalText(data []byte) (err error)

UnmarshalText implements decoding of DocumentURI values.

In particular, it implements a systematic correction of various odd features of the definition of DocumentURI in the LSP spec that appear to be workarounds for bugs in VS Code. For example, it may URI-encode the URI itself, so that colon becomes %3A, and it may send file://foo.go URIs that have two slashes (not three) and no hostname.

We use UnmarshalText, not UnmarshalJSON, because it is called even for non-addressable values such as keys and values of map[K]V, where there is no pointer of type *K or *V on which to call UnmarshalJSON. (See Go issue #28189 for more detail.)

Non-empty DocumentURIs are valid "file"-scheme URIs. The empty DocumentURI is valid.

type URI

type URI = string

A URI is an arbitrary URL (e.g. https), not necessarily a file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL