Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guard against null rootUris #169

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions language-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ let hasWorkspaceFolderCapability = false;
// in the passed params the rootPath of the workspace plus the client capabilities.
let capabilities: ClientCapabilities;
let workspaceFolders = [];
let workspaceRoot: URI;
let workspaceRoot: URI | undefined;
connection.onInitialize((params: InitializeParams): InitializeResult => {
capabilities = params.capabilities;
workspaceFolders = params["workspaceFolders"];
workspaceRoot = URI.parse(params.rootUri, true);
workspaceRoot = params.rootUri ? URI.parse(params.rootUri, true) : undefined;

function hasClientCapability(...keys: string[]) {
let c = params.capabilities;
Expand Down
11 changes: 8 additions & 3 deletions language-service/src/services/yamlDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class YAMLDefinition {
this.promise = promiseConstructor || Promise;
}

public doDefinition(document: TextDocument, position: Position, yamlDocument: YAMLDocument, workspaceRoot: URI): Thenable<Definition> {
public doDefinition(document: TextDocument, position: Position, yamlDocument: YAMLDocument, workspaceRoot: URI | undefined): Thenable<Definition> {
const offset = document.offsetAt(position);

const jsonDocument = yamlDocument.documents.length > 0 ? yamlDocument.documents[0] : null;
Expand Down Expand Up @@ -64,8 +64,13 @@ export class YAMLDefinition {
// So create an actual URI, then .toString() it and skip the unnecessary encoding.
let definitionUri = '';
if (location.startsWith(path.sep)) {
// Substring to strip the leading separator.
definitionUri = Utils.joinPath(workspaceRoot, location.substring(1)).toString(true);
if (workspaceRoot !== undefined) {
// Substring to strip the leading separator.
definitionUri = Utils.joinPath(workspaceRoot, location.substring(1)).toString(true);
} else {
// Can't form an absolute path without a workspace root.
return this.promise.resolve(void 0);
}
}
else {
definitionUri = Utils.resolvePath(
Expand Down