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

Revert "core syntax: strip the path from filename on syntax.get (#1168)" #1322

Merged
merged 2 commits into from
Jun 9, 2023

Conversation

Guldoman
Copy link
Member

@Guldoman Guldoman commented Jan 11, 2023

This reverts commit af6c4bc.

The previous behavior was correct and allowed access to the full path for path-dependant syntaxes.
The correct way to do filename-only matching is prepending the match with the path separator.
Would need testing on Windows to see whether it's necessary to use [\\/], or if / is enough.

The syntaxes that used ^ will have to switch to /.

…-xl#1168)"

This reverts commit af6c4bc.

The previous behavior was correct and allowed access to the full path for path-dependant syntaxes.
@jgmdev
Copy link
Member

jgmdev commented Jan 11, 2023

Instead of simply reverting could you add the two checks? One with path and another without, because other syntax files where failing with the full path.

@Guldoman
Copy link
Member Author

Instead of simply reverting could you add the two checks? One with path and another without, because other syntax files where failing with the full path.

The correct way would be to fix the syntaxes to use /, leaving ^ to be used as project root.

@Guldoman
Copy link
Member Author

The only issue would be with files in the actual root of the project. We could:

  1. prepend / to the filename before checking it
  2. use both versions of the pattern (files = { "^filename$", "/filename$" })

@Guldoman
Copy link
Member Author

Actually, do we care about testing if something is in the project root?
We could just pass abs_filename to syntax.get.
This would allow us to do proper path-based matching, while losing the project-root-based one.

For example the ssh syntax would match the config file even if the project root is the .ssh dir.

@Guldoman Guldoman force-pushed the PR_fix_syntax_path_match branch from eabdc74 to 2d220c5 Compare January 12, 2023 20:42
@Guldoman
Copy link
Member Author

With the last commit, we match the entire path if possible.
This allows for full-path matching (^/etc/fstab$, /%.ssh/config$) regardless of project root.
This also means that we can't match relative to the project root, but I don't think there are many cases where it could have been used.

We now also use common.normalize_path so the path separator problem shouldn't matter anymore.

@jgmdev
Copy link
Member

jgmdev commented Jan 12, 2023

But can we keep support for ^filename$ ? Makes more sense than /filename$

@Guldoman
Copy link
Member Author

I think having it matching just absolute paths makes the most sense, as opposed to matching multiple things.
In the end it's just a matter of replacing ^ with /.

@Guldoman
Copy link
Member Author

Yes, replace ^ with / and add / where applicable.

@jgmdev
Copy link
Member

jgmdev commented Jan 12, 2023

At least that list serves as reference, don't forget to contact the owner of https://github.com/FilBot3/lite-xl-language-containerfile/blob/main/init.lua to apply the change

jgmdev added a commit to pragtical/pragtical that referenced this pull request May 22, 2023
This allows matching full paths in language syntaxes, but we lose the
possibility of matching the project root.
@Guldoman Guldoman force-pushed the PR_fix_syntax_path_match branch from 2d220c5 to 7b99c00 Compare June 9, 2023 13:30
@adamharrison
Copy link
Member

Looks good, adjusted plugins on the 2.2 branch for plugins, and pushed. Merging.

@adamharrison adamharrison merged commit a5e3d97 into lite-xl:master Jun 9, 2023
takase1121 pushed a commit to takase1121/lite-xl that referenced this pull request Aug 19, 2023
…-xl#1168)" (lite-xl#1322)

* Revert "core syntax: strip the path from filename on syntax.get (lite-xl#1168)"

This reverts commit af6c4bc.

The previous behavior was correct and allowed access to the full path for path-dependant syntaxes.

* Use `Doc.abs_filename` to obtain syntax when possible

This allows matching full paths in language syntaxes, but we lose the
possibility of matching the project root.
takase1121 pushed a commit to takase1121/lite-xl that referenced this pull request Aug 19, 2023
…-xl#1168)" (lite-xl#1322)

* Revert "core syntax: strip the path from filename on syntax.get (lite-xl#1168)"

This reverts commit af6c4bc.

The previous behavior was correct and allowed access to the full path for path-dependant syntaxes.

* Use `Doc.abs_filename` to obtain syntax when possible

This allows matching full paths in language syntaxes, but we lose the
possibility of matching the project root.
takase1121 pushed a commit to takase1121/lite-xl that referenced this pull request Aug 19, 2023
…-xl#1168)" (lite-xl#1322)

* Revert "core syntax: strip the path from filename on syntax.get (lite-xl#1168)"

This reverts commit af6c4bc.

The previous behavior was correct and allowed access to the full path for path-dependant syntaxes.

* Use `Doc.abs_filename` to obtain syntax when possible

This allows matching full paths in language syntaxes, but we lose the
possibility of matching the project root.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants