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

Autocomplete on transformed paths #118

Closed
redactedscribe opened this issue Sep 22, 2022 · 4 comments
Closed

Autocomplete on transformed paths #118

redactedscribe opened this issue Sep 22, 2022 · 4 comments

Comments

@redactedscribe
Copy link

redactedscribe commented Sep 22, 2022

I'm trying to transform path autocompletions to use "%20" instead of spaces but the following settings only ever replace the first space in the autocompletion, e.g. I get "../Some%20Folder Name/" as a suggestion. That's an issue as I need every space to be a "%20" for Markdown paths to work. Am I doing something wrong?

"path-autocomplete.transformations": [{
    "type": "replace",
    "parameters": [" ", "%20"],
    "when": {
        "filename": "\\.md$"
    }
}],

But regarding the title of this issue, even if I manually type the correct paths in with all the "%20"s, the next Ctrl + Space I do doesn't suggest anything, presumably because of the path string not matching the paths reported by VS Code. For this reason, it would be great if the extension could look up what is being used as a transformation (in my case "%20" instead of " ") and invert the transformation to know what the path actually is so that an autocompletion can be shown: "../Some%20Folder%20Name/" should be able to trigger autocompletions, for example.

This will only work with simple regex transformations, but in general, I assume people will only use the transformation option to substitute characters so the suggested feature should work for most people. Alternatively, maybe a secondary transformation should be supported "Substitute" to be sure that the rule can be inverted.

Thanks.

v1.22.1

@redactedscribe
Copy link
Author

@mihai-vlc Hello Mihai. Could you kindly inform me whether it is possible to replace all instances of a character in a path using path-autocomplete.transformations? E.g. foo bar baz.md to foo_bar_baz.md (spaces to underscores)?

@mihai-vlc
Copy link
Owner

Support for this has been added in 1.24.0

Please try it out and feel free to reopen the issue if it doesn't match your use case.

  // replace spaces with %20
  {
      "type": "replace",
      "parameters": [ " ", "%20", "g" ],
      "when": {
          "path": ".*routes"
      }
  },

  // replace %20 with spaces when reading the already inserted path
  {
      "type": "inputReplace",
      "parameters": [ "%20", " ", "g" ],
      "when": {
          "path": ".*routes"
    }
  },

@redactedscribe
Copy link
Author

redactedscribe commented May 30, 2023

Thank you! It works great. Unsure why to use "path": ".*routes" over "filename": "\\.md$", but what I have is functioning as expected anyhow.

By the way, the README.md examples wrongly contain mentions of fileName when they should be filename (otherwise it will not work).

@mihai-vlc
Copy link
Owner

The fileName and path can be used for filtering the items/instances where the transformation should be applied.

For the replace transformation considering we selected /home/mihai/a.txt:

  • fileName - regex applied to the basename of the selected suggestion a.txt
  • path - regex applied to the the full path of the selected suggestion /home/mihai/a.txt

For the inputReplace transformation considering that what we typed so far is /home/mihai:

  • path - regex applied to the path inserted so far /home/mihai

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants