type DocumentURI … type URI … // 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. func (uri *DocumentURI) UnmarshalText(data []byte) (err error) { … } // 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 (uri DocumentURI) Path() string { … } // Dir returns the URI for the directory containing the receiver. func (uri DocumentURI) Dir() DocumentURI { … } // DirPath returns the file path to the directory containing this URI, which // must be a file URI. func (uri DocumentURI) DirPath() string { … } // Encloses reports whether uri's path, considered as a sequence of segments, // is a prefix of file's path. func (uri DocumentURI) Encloses(file DocumentURI) bool { … } func filename(uri DocumentURI) (string, error) { … } // ParseDocumentURI interprets a string as a DocumentURI, applying VS // Code workarounds; see [DocumentURI.UnmarshalText] for details. func ParseDocumentURI(s string) (DocumentURI, error) { … } // URIFromPath returns DocumentURI for the supplied file path. // Given "", it returns "". func URIFromPath(path string) DocumentURI { … } const fileScheme … // isWindowsDrivePath returns true if the file path is of the form used by // Windows. We check if the path begins with a drive letter, followed by a ":". // For example: C:/x/y/z. func isWindowsDrivePath(path string) bool { … } // isWindowsDriveURIPath returns true if the file URI is of the format used by // Windows URIs. The url.Parse package does not specially handle Windows paths // (see golang/go#6027), so we check if the URI path has a drive prefix (e.g. "/C:"). func isWindowsDriveURIPath(uri string) bool { … }