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

cmake command returns error "Cannot read property 'uri' of undefined" when called via #1150

Closed
giantmustache opened this issue Mar 31, 2020 · 7 comments
Labels
bug a bug in the product Feature: multiroot
Milestone

Comments

@giantmustache
Copy link

giantmustache commented Mar 31, 2020

Brief Issue Summary

Since the later updates of cmake tools that support multiroot projects, my scripts seem to be broken that make use of the api and call the cmake commands. As an example I am using the Ego powertools plugin and call the following script:

// relativeTargetPath.js
exports.execute = async (args) => {
    const vscode = args.require('vscode');
    return vscode.commands.executeCommand('cmake.buildDirectory');
};

The executeCommand call return the error Cannot read property 'uri' of undefined.
Reverting back to version 1.2.3 of cmake tools makes the script work fine.
My project is using a multi root setup.

Most interesting is the fact that calling the same command from within a task with string resolve does work:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "echo",
      "type": "shell",
      "command": "echo ${cmake.buildDirectory}"
    }
  ]
}

Expected:

executeCommand() should give the same results as "${cmake.buildDirectory}".

Apparent Behavior:

executeCommand() returns Cannot read property 'uri' of undefined.

Platform and Versions

  • Operating System: Windows 10
  • CMake Version: 3.16.3
  • VSCode Version: 1.43.2
  • CMake Tools Extension Version: 1.3.1

Other Notes/Information

I first posted the bug in vscode powertools, but I figured out that reverting to 1.2.3 made it work, so I really believe this is a cmake tools issue.

See egodigital/vscode-powertools#35

@bobbrow
Copy link
Member

bobbrow commented Mar 31, 2020

Thanks for reporting this. I submitted a PR to fix it. The command is uspposed to work without passing in the folder path, but you might consider updating your extension to support multi-root by passing in the folder when you execute the command.

@giantmustache
Copy link
Author

I tried the following in the current release 1.3.1.

My workspace looks like this:

{
	"folders": [
		{
			"name": "MASTER",
			"path": "."
		},
		{
			"name": "COMMON",
			"path": "../COMMON"
		},
		{
			"name": ".azuredevops",
			"path": "../.azuredevops"
		}
	]
}

And then I changed my script to:

// relativeTargetPath.js
exports.execute = async (args) => {
    const vscode = args.require('vscode');
    return vscode.commands.executeCommand('cmake.buildDirectory', 'MASTER');
};

That didn't return anything. Then I tried it with: '.', because maybe I needed to use the path. But no results. The PR should definitely fix it though.

@bobbrow
Copy link
Member

bobbrow commented Apr 1, 2020

We use the vscode.workspace.getWorkspaceFolder API to convert the path to a WorkspaceFolder, so yeah, 'MASTER' won't likely work. I believe you could also call this API yourself and pass in the WorkspaceFolder directly.

@giantmustache
Copy link
Author

That's great!

I changed my script to the following for now. Awaiting new release of vscode-tools:

// relativeTargetPath.js
exports.execute = async (args) => {
    const vscode = args.require('vscode');
    const workspace = vscode.workspace.workspaceFolders[0];

    return vscode.commands.executeCommand('cmake.buildDirectory', workspace);
};

@andreeis
Copy link
Contributor

CMake Tools 1.4.0 Beta is available on GitHub.
https://github.com/microsoft/vscode-cmake-tools/releases/tag/1.4.0-beta

Please try it out and let us know if you encounter any issues.

@giantmustache
Copy link
Author

giantmustache commented May 19, 2020

My scripts indeed work without the workaround now, so when 1.4.0 is released this issue can be closed.

@andreeis
Copy link
Contributor

This fix is available in CMake Tools #1.4.0 which has been released.

@github-actions github-actions bot locked and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug a bug in the product Feature: multiroot
Projects
None yet
Development

No branches or pull requests

3 participants