question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

unresolved import depending how you open the file

See original GitHub issue

rust-analyzer: rust-analyzer fdd49b971 2021-11-17 dev rustc: rustc 1.58.0-nightly (c9c4b5d72 2021-11-17)

nvim and coc settings: https://gitlab.com/Ricky12Awesome/dotfiles/-/tree/main/.config/nvim project I’ve tested this on: https://github.com/Ricky12Awesome/sysusage

Related to: #898

When opening the project directory and you select the file you want to edit, it will give you this error but, if you open the directory but select Cargo.toml first, it doesn’t give you the error

this seems to be an issue when it starts rust-analyzer, since if you just open the directory and do CocInfo, it isn’t started yet but when you select a file (like Cargo.toml) then it gets started

so one way to fix this is if you open a directory that contains Cargo.toml then it should start the RA server

could also just be an issue with my vim config and nerdtree

https://user-images.githubusercontent.com/29931568/142352252-3a754ee6-6e6b-4d45-8e05-21779ee4060f.mp4

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
fannheywardcommented, Nov 18, 2021

The rust-analyzer needs a workspace root to work. If you do vim path/to/project, the workspace root is your cwd. After you cd path/to/project, the workspace root will be resolved to path/to/project.

0reactions
Ricky12Awesomecommented, Nov 18, 2021

think I figured out the cause of this, if you change directory with in your vim config, it seems to not be reflected to coc and it’s workspaces, but if you change it manually (make sure anything that changes cd is commented out in vim config), it works fine

I switch from NERDTree to coc-explorer, but this should apply to both

this is how I’m launching explorer, with this, the explorer starts fine, but it’s whatever directory you execute the command in

autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists('s:std_in') |
  \ exe join(['cd '.argv()[0], 'CocCommand explorer'], ' | ') | wincmd p | enew | endif

if you comment that out and just do it manually, it works fine no problem but for don’t comment it out, and try and do this, it doesn’t work for some reason

cd path/to/directory | CocCommand explorer

EDIT:

Adding a delay does seem to fix, but there has to be some event that could trigger this, cuase just adding a delay is a hacky way of doing it

func AutoStartExplorer(timer)
  if argc() == 1 && isdirectory(argv()[0]) && !exists('s:std_in')
    exe join(['cd '.argv()[0], 'CocCommand explorer '], ' | ') | wincmd p | enew 
  endif 
endfunc

autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * call timer_start(300, 'AutoStartExplorer')
Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Pylint "unresolved import" error in Visual Studio Code
The best solution for now is to create a .env file in your project root folder. Then add a PYTHONPATH to it like...
Read more >
Unresolved import of local python file if main script is not at ...
Issue: When importing your own python modules which are in the workspace folder, but the main script is not in the root directory...
Read more >
Dependency Walker Frequently Asked Questions (FAQ)
When you first open a module in Dependency Walker, it only shows implicit, ... get a "Warning: At least one module has an...
Read more >
How to solve "unresolved import" (VS Code + Anaconda ...
Solving the " unresolved import " error in VS Code with 1 easy step!
Read more >
Upgrade your Node app: From CommonJS to ES Modules
Local file imports require a file extension. Every import must end with .js (or .mjs depending on your choice). You might haven't seen...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found