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

Editor Custom Labels: Support negative indices to access start of the file path #209619

Closed
benibenj opened this issue Apr 5, 2024 · 5 comments · Fixed by #209869
Closed

Editor Custom Labels: Support negative indices to access start of the file path #209619

benibenj opened this issue Apr 5, 2024 · 5 comments · Fixed by #209869
Assignees
Labels
feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders verification-found Issue verification failed verified Verification succeeded workbench-tabs VS Code editor tab issues
Milestone

Comments

@benibenj
Copy link
Contributor

benibenj commented Apr 5, 2024

Currently, the editor does not support customizing file labels in a way that would allow filenames to be prefixed with the name of the application or folder from the start of the path. This limitation affects projects structured in a monorepo setup, particularly when files are deeply nested within application-specific directories.

Supporting negative indices for ${dirname(N)} could solve this problem. This would enable accessing folder names starting from the beginning of the path. Implementing negative indices would cater to the needs of projects with files at various nesting levels within their structure.

@benibenj benibenj added feature-request Request for new features or functionality workbench-tabs VS Code editor tab issues labels Apr 5, 2024
@benibenj benibenj added this to the April 2024 milestone Apr 5, 2024
@benibenj benibenj self-assigned this Apr 5, 2024
@Destroy666x
Copy link

Is the reasoning not the other way round or am I misunderstanding how it currently works? E.g. I'd like to access last 2 parts of the path, but the description of the settings suggests that only the single final and the starting folders can be accessed.

@benibenj
Copy link
Contributor Author

benibenj commented Apr 7, 2024

@Destroy666x, For the following path you will get the following values:

Path: root/parentFolder/folder/file.ext

  • ${dirname}: folder
  • ${dirname(0)}: folder
  • ${dirname(1)}: parentFolder
  • ${dirname(2)}: root

With negative indices:

  • ${dirname(-1)}: root
  • ${dirname(-2)}: parentFolder
  • ${dirname(-3)}: folder

@Maksym-L
Copy link

Maksym-L commented Apr 8, 2024

Here is an example of the mono repo: https://github.com/vuejs/core/tree/main/packages
It has a root and multiple projects in the packages folder. It is common to make changes in multiple "packages" at once, and it would be convenient if we could identify files by the ${dirname(-2}.

Example:

  • packages/runtime-core/src/helpers/resolveAssets.ts -> resolveAssets.ts (runtime-core)

@vscodenpa vscodenpa added unreleased Patch has not yet been released in VS Code Insiders insiders-released Patch has been released in VS Code Insiders and removed unreleased Patch has not yet been released in VS Code Insiders labels Apr 8, 2024
@benibenj benibenj added the verification-needed Verification of issue is requested label Apr 22, 2024
@benibenj
Copy link
Contributor Author

benibenj commented Apr 22, 2024

Verification steps:

  1. Create a custom editor label. The template should include ${dirname(N)}, for which N is a negative number.
  • For example, add in workbench.editor.customLabels.patterns, item: ** value: ${dirname(-1)}/${filename}
  1. Open a file which matches the pattern specified in step 1.
  • For the example specified in step 1: every file matches the pattern
  1. The editor tab should have set the correct folder name for ${dirname(N)}.
    Here an explanation on how negative indices work: Editor Custom Labels: Support negative indices to access start of the file path #209619 (comment)
  • For the example specified in step 1: the name of the editor in the tab should start with the top level folder the file is located in. In the vscode repo the file abstractTree.ts would have the custom name src/abstractTree

@aiday-mar aiday-mar added the verified Verification succeeded label Apr 24, 2024
@aiday-mar
Copy link
Contributor

I have followed the steps for the verification and the settings file is renamed to ${dirname(-1)}/settings. The TS files are renamed correctly to src/<filename>. Is this expected?

Screen.Recording.2024-04-24.at.14.08.48.mov

@aiday-mar aiday-mar added verification-found Issue verification failed and removed verification-needed Verification of issue is requested labels Apr 24, 2024
@microsoft microsoft locked and limited conversation to collaborators Jun 9, 2024
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 insiders-released Patch has been released in VS Code Insiders verification-found Issue verification failed verified Verification succeeded workbench-tabs VS Code editor tab issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants