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

Variable substition: ${packagePath} #27162

Closed
omniscient opened this issue May 23, 2017 · 7 comments
Closed

Variable substition: ${packagePath} #27162

omniscient opened this issue May 23, 2017 · 7 comments
Assignees
Labels
feature-request Request for new features or functionality variable-resolving

Comments

@omniscient
Copy link

In the spirit of #396, please consider adding a new variable that can be used in launch.json and that will refer to the package directory (packageRoot) of the currently opened file within the editor.

This is going to be useful to reduce the number of profiles necessary to debug each package. As an example, here's what we have to do currently such that we can debug our tape unit tests directly from the code editor:

Given that we have a mono repo structure like this:

Root
  package.json
  Packages
    api
      package.json
      src
      dist
    orm
      package.json
      src
      dist

Given we develop in Typescript and we resolve the current file name using ${fileBasenameNoExtension}, Given we have both a "api" package and a "orm" package in a git mono repo,
We are stuck doing this to debug our tests inside the code editor:

{
        "type": "node",
        "request": "launch",
        "name": "Debug::api current test",
        "sourceMaps": true,
        "protocol": "inspector",
        "stopOnEntry": false,
        "program": "${workspaceRoot}/node_modules/tape/bin/tape",
        "args": [
          "${workspaceRoot}/packages/api/dist/_test/**/${fileBasenameNoExtension}.js"
        ],
        "cwd": "${workspaceRoot}/packages/api",
        "console": "internalConsole"
      },
      {
        "type": "node",
        "request": "launch",
        "name": "Debug::orm current test",
        "sourceMaps": true,
        "protocol": "inspector",
        "stopOnEntry": false,
        "program": "${workspaceRoot}/node_modules/tape/bin/tape",
        "args": [
          "${workspaceRoot}/packages/orm/dist/_test/**/${fileBasenameNoExtension}.js"
        ],
        "cwd": "${workspaceRoot}/packages/orm",
        "console": "internalConsole"
      }

The request is for a variable that identifies the root directory of each package so that we could re-write our launch.json like this:

 {
        "type": "node",
        "request": "launch",
        "name": "Debug unit test with tape",
        "sourceMaps": true,
        "protocol": "inspector",
        "stopOnEntry": false,
        "program": "${workspaceRoot}/node_modules/tape/bin/tape",
        "args": [
          "${packageRoot}/dist/_test/**/${fileBasenameNoExtension}.js"
        ],
        "cwd": "${packageRoot}",
        "console": "internalConsole"
      }
@omniscient omniscient changed the title As a mono repo user, I need a variable to that identifies the "package path" within launch.json As a mono repo user, I need a variable that identifies the "package path" within launch.json May 23, 2017
@isidorn
Copy link
Contributor

isidorn commented May 24, 2017

I believe that ${workspaceRootFolderName} solves your problem.
The whole list of variables can be found here https://code.visualstudio.com/docs/editor/tasks#_variable-substitution

If none of them solve your issue than please let me know for the path
/a/b/c/d/e.txt and the repository is /a/b what do you want extracted with the variable

@isidorn isidorn added the info-needed Issue requires more information from poster label May 24, 2017
@omniscient
Copy link
Author

@isidorn Thanks for your quick response on this. As identified above, we are already using the ${workspaceRoot} variable which is identical to ${workspaceRootFolderName} in that it actually returns the root directory. In a git mono repo, you have multiple root, one for each package. By default, a mono repo has a folder into which all package (what would equate to a single git repo) lives in. The standard i've seen is to create subfolder named packages. Under that 'packages' folder lives each different component. There is really 2 things I think for this to work.

  1. A way to tell vscode that you have multiple packages and that the package folder is named 'xyz'
  2. A way, by using the configured package root, to return into a variable each package root folder.

Let's take my example above. On my system I have my git repository in c:\git\myrepo. Within the myrepo git repository, I have a structure as identified above:

myrepo
  package.json
  Packages
    api
      package.json
      src
      dist
    orm
      package.json
      src
      dist

Given the above example, that means I have c:\git\myrepo\packages set as my root for every different package that I manage in that mono repo. In the example, my mono repo handles 2 different packages that are in the following folders on my system:

  1. api which lives in c:\git\myrepo\packages\api
  2. orm which lives in c:\git\myrepo\packages\orm

The request is that in launch.json, I have access to a new variable $(packageRoot} that knows that when I got a file open under the api project, for example c:\git\myrepo\packages\api\src\__test\blabla.ts, the new variable returns c:\git\myrepo\packages\api. Similarly, when I have a file open in the orm project, that new variable would return c:\git\myrepo\packages\orm

Hope this makes sense, let me know if you need more information.

@isidorn
Copy link
Contributor

isidorn commented May 29, 2017

@omniscient thanks for providing more information however what you seem to be needing seems very specific for mono debugging. On the VSCode side we are language agnostic and do not provide any variable subsitition that is speicifc for some language.
This should in theory be handled by the mono debug extension, however our current extension API is not strong enough to support this use case.

Due to the following leaving this open as a feature request and assiging to backlog.

@isidorn isidorn added feature-request Request for new features or functionality and removed info-needed Issue requires more information from poster labels May 29, 2017
@isidorn isidorn changed the title As a mono repo user, I need a variable that identifies the "package path" within launch.json Variable substition: ${packagePath} May 29, 2017
@isidorn isidorn added this to the Backlog milestone May 29, 2017
@isidorn isidorn removed their assignment May 29, 2017
@omniscient
Copy link
Author

omniscient commented May 29, 2017

@isidorn : I am sorry to have to digress here but to be 100% clear, nowhere did I mention a programming language of any sort. What I am talking about is monolithic version control using git.

Would you mind taking a 2nd look at this with that fact in mind? I would really appreciate if you could at least indicate where/what would need to be changed and how, at a high-level, it could done? Maybe I could PR it for you guys if it's not too bad?

Once again, we are talking about a way to identify, that 1, we are dealing with a mono repo and 2, we have a variable that identifies the packages root folder.

@isidorn
Copy link
Contributor

isidorn commented May 30, 2017

Thanks for additional clarification. This sounds like a very speicifc feature request.

Code pointer https://github.com/Microsoft/vscode/blob/master/src/vs/workbench/services/configurationResolver/node/configurationResolverService.ts#L48

We accept PRs, however keep in mind that if it is too complex or too language specific we will not accept it.
Also keep in mind that we currently have no code that detects the type of a repo. Due to that I believe this would be hard to do.

@jcrben
Copy link

jcrben commented Jun 3, 2018

Would #25786 get the job done? It helps to get into the relative nested folders.

@jrieken jrieken added the debug Debug viewlet, configurations, breakpoints, adapter issues label Oct 9, 2019
@isidorn isidorn removed the debug Debug viewlet, configurations, breakpoints, adapter issues label Oct 9, 2019
@alexr00
Copy link
Member

alexr00 commented Nov 5, 2020

I think there is a way you can do this already.

  1. Specify an environment variable that has the relative path to your packages folder in VS Code's workspace settings. Example:
	"terminal.integrated.env.linux": {
		"packagePath": "packages"
	},
  1. Use that variable in you launch.json. Example:
 {
        "type": "node",
        "request": "launch",
        "name": "Debug unit test with tape",
        "sourceMaps": true,
        "protocol": "inspector",
        "stopOnEntry": false,
        "program": "${workspaceRoot}/node_modules/tape/bin/tape",
        "args": [
          "${workspaceRoot}/${env:packagePath}/dist/_test/**/${fileBasenameNoExtension}.js"
        ],
        "cwd": "${workspaceRoot}/${env:packagePath}",
        "console": "internalConsole"
      }

@alexr00 alexr00 closed this as completed Nov 5, 2020
@alexr00 alexr00 removed this from the Backlog milestone Nov 5, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Dec 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality variable-resolving
Projects
None yet
Development

No branches or pull requests

5 participants