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

feat: resolve package urls when using gf or gF #392

Merged
merged 3 commits into from
Oct 11, 2024
Merged

feat: resolve package urls when using gf or gF #392

merged 3 commits into from
Oct 11, 2024

Conversation

sidlatau
Copy link
Collaborator

@sidlatau sidlatau commented Oct 4, 2024

No description provided.

@sidlatau sidlatau linked an issue Oct 4, 2024 that may be closed by this pull request
1 task
@Dieterbe
Copy link

Dieterbe commented Oct 4, 2024

here's what happens when i run 'gf' on lib/backend/muscles.dart: (with nvim launched as nvim code/ptc and the lib directory exists directly inside of code/ptc)

edit: the same happens when i run 'gf' on a runtime error on a path of the form 'package:ptc/backend/movements.dart'

error

@sidlatau
Copy link
Collaborator Author

sidlatau commented Oct 4, 2024

What flutter version do you use? Is there package_config.json file in REPO_ROOT/.dart_tool directory? This file is used to resolve URLs, but it is generated only in recent flutter versions.
image

@Dieterbe
Copy link

Dieterbe commented Oct 4, 2024

flutter --version
Flutter 3.22.3 • channel stable • ssh://[email protected]/flutter/flutter.git
Framework • revision b0850beeb2 (3 months ago) • 2024-07-16 21:43:41 -0700
Engine • revision 235db911ba
Tools • Dart 3.4.4 • DevTools 2.34.3

cat code/ptc/.dart_tool/package_config.json -> https://gist.github.com/Dieterbe/8fa29d233b119bbf07d6926662338527

@sidlatau
Copy link
Collaborator Author

sidlatau commented Oct 6, 2024

@Dieterbe could you test PR again? I fixed a couple of possible issues.

@Dieterbe
Copy link

Dieterbe commented Oct 6, 2024

this is while pressing 'gf' on a file with path lib/... which shouldn't require any path adjustment (because lib is inside code/ptc and i ran nvim code/ptc) - i doublechecked that the file code/ptc/lib/ui/muscle_screen.dart indeed exists. image

@sidlatau
Copy link
Collaborator Author

sidlatau commented Oct 7, 2024

@Dieterbe it is hard to understand what is going on from the screenshot. For me both uris with package: or without it work as expected. Could you paste the output of :messages after trying to use gf? Does command work for other links? Maybe you are using auto-session plugin? I had some caching problems with it, that caused gf issues.

@Dieterbe
Copy link

Dieterbe commented Oct 7, 2024

I use github.com/LazyVim/starter without any customizations, other than this file:

cat lua/plugins/core.lua
return {
  {
    "LazyVim/LazyVim",
    opts = {
      colorscheme = "tokyonight",
    },
  },
  {
    "akinsho/flutter-tools.nvim",
    lazy = false,
    branch = "resolve-url",
    dependencies = {
      "nvim-lua/plenary.nvim",
      "stevearc/dressing.nvim", -- optional for vim.ui.select
    },
    config = true,
  },
}
~/.c/nvim ❯❯❯ grep -Ri auto-session
~/.c/nvim ❯❯❯   

so, i reproduced the same situation as in my previous comment, and :messages says this:

"~/code/ptc/lib/backend/muscles.dart" 246L, 5877B
1 change; before #1  58 seconds ago
"~/code/ptc/lib/backend/muscles.dart" 246L, 5877B
"~/code/ptc/lib/backend/muscles.dart" 246L, 5875B
"~/code/ptc/lib/main.dart" 71L, 2437B
"~/code/ptc/lib/main.dart" 72L, 2480B
Type  :qa  and press <Enter> to exit Nvim
...azy/flutter-tools.nvim/lua/flutter-tools/resolve_url.lua:92: Cannot find package_config.json file
stack traceback:
	[C]: in function 'error'
	...azy/flutter-tools.nvim/lua/flutter-tools/resolve_url.lua:92: in function <...azy/flutter-tools.nvim/lua/flutter-tools/resolve_url.lua:84>
E15: Invalid expression: "v:lua.require('flutter-tools.resolve_url').resolve_url(v:fname)"
E447: Can't find file "lib/ui/muscles_screen.dart" in path

i have checked that i have the latest commit installed btw ( 77dd736 fix: pick closest package_config instead of picking from cwd first (2 days ago)) - i also checked this yesterday, FWIW

@Dieterbe
Copy link

Dieterbe commented Oct 7, 2024

aha, i found what triggers the problem.

when i am in $HOME, and run nvim code/ptc, that's when i have the above issues (but vim seems to work fine otherwise, including starting :FlutterRun, which led me to believe this was an okay way to do it)
when i cd into $HOME/code/ptc and then run nvim, then it seems to work for the above case (where the path printed is already correct) as well as the original casewith a path like package:ptc/backend/movements.dart

@sidlatau
Copy link
Collaborator Author

@Dieterbe did you tested with the latest changes? 77dd736 should actually use buffer path, previously it tried to find package_config.json in CWD. So even if you opened vim with a path argument, it should construct references correctly.

@Dieterbe
Copy link

i did actually. strange. and it works fine on your system when you try something similar?

@sidlatau
Copy link
Collaborator Author

Yes, it works for me. So I think I will merge this PR, it works in most cases, we may solve edge cases on separate PRs.

@sidlatau sidlatau merged commit 6bf887b into main Oct 11, 2024
6 of 7 checks passed
@sidlatau sidlatau deleted the resolve-url branch October 11, 2024 05:26
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

Successfully merging this pull request may close these issues.

[BUG] 'flutter run' not compatible with 'open file' ?
2 participants