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

Test: Custom Editor Labels #208388

Closed
3 tasks done
benibenj opened this issue Mar 22, 2024 · 5 comments
Closed
3 tasks done

Test: Custom Editor Labels #208388

benibenj opened this issue Mar 22, 2024 · 5 comments

Comments

@benibenj
Copy link
Contributor

benibenj commented Mar 22, 2024

Refs: #41909

Complexity: 5

Create Issue


In this iteration we added support to change the labels of open editors (Name displayed in the tabs and open editors view). Users can do this by adding an entry in the workbench.editor.customLabels.patterns setting. An entry consists of:

  • Item: Glob Pattern that matches the file path of the editor. If the pattern is a relative pattern, then it is matched against the relative file path of the editor (relative to current workspace). If the pattern is an absolute pattern (starts with /), then it is matched against the absolute file path of the editor.
  • Value: Template which defines how the label should be rendered. The template can include the following variables which will then be replaced with the respective values of the current matched pattern:
    • ${extname}: The file extension of the current editor (txt, py, ts).
    • ${filename}: The name of the file of the current editor. Does not include the extension. (root/parentFolder/folder/file.txt => file)
    • ${dirname}: The name of the folder the file of the current editor is placed in. (root/parentFolder/folder/file.txt => folder)
    • ${dirname(N)}: The name of the nth parent folder in which the file is located:
      • ${dirname(0)} is the same as ${dirname}: (root/parentFolder/folder/file.txt => folder)
      • ${dirname(1)} is the parent folder of ${dirname(0)}: root/parentFolder/folder/file.txt => parentFolder
      • ${dirname(2)} is the parent folder of ${dirname(1)}: root/parentFolder/folder/file.txt => root
      • ${dirname(3)} is the parent folder of ${dirname(2)}: For the file path root/parentFolder/folder/file.txt, root is at level 2 and does not have a parent folder. In this case there is no value we can replace ${dirname(3)} with so we render the variable name as is. The reason we render the variable in the name is so that the user is aware that his template doesn't properly work for his case and hence should fix it.

Testing:

  1. Add a simple patern and a template and see how the editor names are changed. A very simple option could be:
  • Pattern: **, Template: Hello World:
  • The ** pattern will match with every single editor. This means no matter which editor you open it will be called Hello World. Check both the name rendered in the tab and the name rendered in the open editors view

Code_-_Insiders_qcYQIAkbwT

  1. Set workbench.editor.customLabels.enabled to false: All editors will have the REAL name again.
  2. Set workbench.editor.customLabels.enabled back to true: All editor will have the Hello World name again
  3. Remove the previously added pattern.
  4. Add a more complex pattern. Here an example for the AbstractTree.ts file in the vscode repository located at src/vs/base/browser/ui/tree/abstractTree.ts. Open the file and add the pattern, see how it will be renamed.
  • Pattern: src/**/abstractTree.ts, Template: ${dirname}/${filename}:
  • The file will now be rendered as tree/abstractTree. As this is the only editor that matches with the pattern, no other editor is renamed.
    Code_-_Insiders_LRL82rvjHO
  1. Add one more pattern (you should then have 2 patterns total) which will also match with that file. Make the pattern more specific then the previous one. For example:
  • Pattern: src/vs/base/**/abstractTree.ts, Template: ${dirname(1)}/${dirname}/${filename}:
  • The file will now be rendered as ui/tree/abstractTree because this pattern is more specific compared to the pattern previously

Code_-_Insiders_KBjRFSOVEp

@benibenj benibenj added this to the March 2024 milestone Mar 22, 2024
@hediet hediet removed their assignment Mar 25, 2024
@hediet
Copy link
Member

hediet commented Mar 25, 2024

Super nice feature!

@andreamah
Copy link
Contributor

Nifty feature!

@andreamah andreamah removed their assignment Mar 25, 2024
@paulacamargo25 paulacamargo25 removed their assignment Mar 25, 2024
@paulacamargo25
Copy link
Contributor

Nice work 👍 ❤️

@ronsig
Copy link

ronsig commented May 1, 2024

If I want my vscode extension to set the workbench.editor.customLabels.enabled setting to true, and more importantly, the workbench.editor.customLabels.patterns setting inside its contribution point in package.json, how would I go about doing it?
Thanks

@benibenj
Copy link
Contributor Author

benibenj commented May 2, 2024

@ronsig You can use configurationDefaults to set the default value of a setting. We are working on a better way for extensions to provide patterns such that a user can have multiple extensions providing patterns. Tracking this issue here: #211632

@microsoft microsoft locked and limited conversation to collaborators Jun 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants