VScode Haskell Go To Definition doesn't work for some symbols - visual-studio-code

I'm getting started with Haskell and VSCode. I've forked and downloaded a repo with Haskell code. I've followed instructions for setting up a nix-shell correctly for this repo. I can successfully invoke cabal build and haskell-language-server for week 1 examples.
I've started up VSCode from within nix-shell and I can see that the language server is reporting symbol information to VSCode. For example:
However, I often find that if I try to Go To Definition VSCode reports that no definition is found:
For many of these symbols I find that if I hover my cursor over the symbol I'm shown where the symbol is defined:
Othertimes, I find that Go To Definition correctly resolves. For example, AuctionSchema on this line resolves correctly, while AuctionSchema on this line does not.
Why does Go To Definition only sometimes work? Is there a way to fix this?

I use emacs within NixOS, and I find that definitions are only found when they’re within the project I’m working on. Sometimes if I’m in src and the definition is in lib it won’t find it either. I just assumed that Haskell Language Server cannot use Cabal or Hpack to find definitions, but only follows types within the directory branch the current source resides. Yep, that’s annoying, but it seems to be what’s currently on offer.

Related

Full Rust setup in VSCode/Atom Issue

This is a long post, sorry.
I have been trying to start a project, using Rust, but ran into a problem: it just does not work correctly on Linux in VSCode/Atom.
Wasted 3 days, searching online, trying different tutorials/videos - nothing worked + most of the material is from 2017. I have tried Matrix chat, but no one knew what to do. Git too has no solution as people keep suggesting very random things, like "change this variable in toml file to something else, and back again"
Git: https://github.com/rust-lang/rls-vscode/issues/513
I installed (and re-installed rust many times in the last 3 days), and it works just fine from the terminal, but not in the Editor.
Two Issues:
Editors don't see any crates, so you can't run your code from the editor.
Autocomplete does not work (only works on std, not on extra crates you add).
What I did (out of many other things):
install Rust (on Manjaro and Debian computers): curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Tried stable, beta, nightly (for racer)
Just did a clean install again:
stable installed - rustc 1.40.0 (73528e339 2019-12-16)
Rust is installed now. Great!
Installed Rust (rls) rust-lang.rust extension in VSCode (and rust in Atom)
Created a new project: cargo new test_proj and added new rand = "0.6" to [dependencies] and used cargo build. It did build rand
Added "rust-client.enableMultiProjectSetup": true to the settings file to avoid a warning: A Cargo.toml file must be at the root of the workspace in order to support all features. Alternatively set rust-client.enableMultiProjectSetup=true in settings. by Rust (rls)
I also install 'code runner' extension that I use with Python, C++, and Java, to run the code from within the editor.
So now I have just the main func and it runs just fine from the editor:
Now I add rand and it seems to work, and does SOME auto-completion...
But now it stops working:
OK, I will finish the code and try running it, And now we can't run it anymore as the crate is missing:
OK, let's try Ctrl + Shift + B and try cargo build:
For some odd reason, it is looking in /media/Work/Work/rust_code and not in /media/Work/Work/rust_code/test_proj/
One last thing: let's try running in the terminal:
So it does work just fine.
Sorry for the long post, but I have wasted 3 days now and it still can't get it up and running. Did anyone manage to set this up at all?
It has to be Atom or VSCode as I have all of the other languages/projects setup there + VSCode is listed on the official Rust website, so I presume it should work.
Basically, out of two editors (VSCode and Atom), that have Debugging capabilities, unlike Intellij Rust, both don't work for me and I just can't code in Rust as tools are literally broken/not mature enough for productive work. Please let me know if I am wrong and it is just a case of one little flag, that everyone forgets to mention, is missing in some config.
Short Version
Assuming I understand the issue correctly. Then the various build issues boil down to different ways you're trying to build the project, and attempting to do so in different directories.
TL;DR: The directory you have open in VSCode is the rust_code directory. Close it and instead open rust_code/test_proj. Now the Rust: cargo build (or Rust: cargo run) should work.
Long Version
Editors don't see any crates, so you can't run your code from the editor.
The Rust: cargo build task isn't working, because the directory you have open isn't a "Rust project" (Cargo package), it's a directory containing another directory, which is a Rust project.
Looking at your screenshot shows this, look at how the top line says rust_code/test_proj:
When you execute the task, Cargo is complaining that rust_code/Cargo.toml doesn't exist, which is true since it's located in rust_code/test_proj/Cargo.toml
If you look at the output of this screenshot, you can see that is the case:
Here you're executing cargo run manually. But the important difference is that you're inside the rust_code/test_proj directory.
Lastly simply executing rustc main.rs is failing since you aren't passing the arguments needed. So rustc doesn't know anything about your dependencies.
Try executing cargo build -v then you can see all the arguments that Cargo is passing to rustc.
Autocomplete does not work (only works on std, not on extra crates you add).
Try and open a directory that contains a Cargo.toml, then code completion should work for dependencies. If I don't, then I get the following notification, and code completion only works for the standard library as you said. That being said, RLS is weird sometimes.
If I had to guess, then I think RLS compiles the code, and at some stage extracts the needed information. Thus if the code doesn't compile, then code completion could be affected. But this is 100% an educated guess.
Alternatively, I have heard praise about using IntelliJ + the Rust plugin, but I haven't used it myself yet.
I have figured out one part: problems with running your code from within the VSCode. I had to modify default code-runner command for rust:
Original command:
"rust": "cd $dir && rustc $fileName && $dir$fileNameWithoutExt",
Changed to:
"rust": "if [ $(basename $dir) = 'examples' ]; then cargo run --example $fileNameWithoutExt; else cargo run; fi",
And now it works, and I can run my code quickly.
Part 2: Autocomplete still is very very bad, unfortunately. I am using RLS. there is this thing racer. Is it a better choice?
Alternatively, I have heard praise about using IntelliJ + the Rust
plugin, but I haven't used it myself yet.
As I mentioned in my previous post, IntelliJ, free edition does not have a debugger from what I can see. I need it.
I am wondering how people get a good autocomplete from Rust?

"List All References" not available in context menu in VSC 1.29.1

I recently upgraded to VS Code 1.29.1 on my Ubuntu virtual machine and was very excited to try out the new List all References preview, but I can't seem to invoke it anywhere. It isn't in the context menu, and trying View: Show Reference Search through the Command Palette does nothing.
Image: No "List All References" option in the context menu when highlighting a function name.
Why does the option not appear, and is there anything I can do to enable it?
My working context:
I'm working on Ubuntu 14.01 LTS and this is for a C project; all of the files in the workspace are *.c, *.h, Makefiles, and perl scripts. I have Intellisense for C/C++ enabled with the ms-vscode.cpptools extension. The only other Marketplace extensions I have installed are color/icon theme-related. Symbol searching, go/peek to declaration/definition, quick info, error squiggles, etc. are all working properly.
Things I've tried:
verified that I'm actually using version 1.29.1 via the Help>About menu option (and confirmed multiline regex searching works)
skimmed the GitHub repo for both open and closed issues and didn't find any similar issues
searched the docs and patch notes
tried various .c and .h files within the workspace.
I'm not familiar enough with the extension and language provider architecture to know where to go from here, and I couldn't glean any caveats from the docs about the new List All References feature, so any help is appreciated.
The List All References feature is based on Find All References, which is supposed to be implemented by the language provider. In my case, the ms-vscode.cpptools language provider has not implemented Find All References, so the List All References feature is unavailable.
(I realized the one thing I hadn't checked were the issues in vscode-cpptools.)
Relevant issue: https://github.com/Microsoft/vscode-cpptools/issues/15#issuecomment-438905148
I guess as a PSA, if you're on VSC1.29.1 and don't have the List All References option, look to your language provider.

Allegro 5 - Cosmic Protector Demo

I'm new to C++ and Allegro 5 but have been able to follow tutorials online and am able to build and compile several smaller projects successfully.
I cannot however get the demo project named Cosmic Protector to run and would like to at least learn what is wrong.
Unfortunately, I can't give you much to go on.
A window opens briefly and then closes, leaving the console open with the message..
process 6400 exited with code 255
If you have this demo running in VC 2017 with the latest release of Allegro 5 (5.2.4) installed via Nuget, I'd like to know that even.
The source for this program is available at...
https://github.com/liballeg/allegro5/tree/master/demos/cosmic_protector
Thank you, Jack
The allegro example programs and demos are usually built with CMake alongside the Allegro library. I just tested the CMake build of Allegro 5 with VS2017 on Windows 10 and it builds the Cosmic Protector demo successfully. You have to move the allegro dlls into the same directory as the exe, but other than that it runs perfectly.
As to why it's not working for you, cosmic protector depends on a data directory that holds it's resources. The working directory may be wrong, which would cause it to be unable to find resources. The data dir needs to be copied alongside the executable.
You can set the working directory to $(OutDir) under Debugging in Project->Properties and then it should find any data in the same directory as the exe.
How are you building cosmic protector?
Thanks to BugSquasher, I now have this working.
Here's how...
Start Visual Studio 2017
Create New Project of type Windows Console Application.
Name project CosmicProtector and save it in appropriate place on my HDD.
Disable precompiled headers and delete the any .h and .cpp
files associated with the new project regarding precompiled headers.
(for example pch.h)
Install Allegro 5.2.4 via Nuget.
In Visual Studio, navigate to Project Settings/Properties and ensure all
Allegro addons are enabled.
Copy the Cosmic Protector SRC and Header files and paste them into my
project directory.
Next in Visual Studio Project, Add the Source and Header files
respectively.
Rather stupidly, the step I had missed and that your reply brought my attention to was...
Copy the data directory and paste this into my project directory in the
applicable location.
Now build...
The project built right away, except for some errors reported in Game.cpp, GUI.cpp and Render.cpp
One error in Game.cpp, this being an instance of...
error C4996 'snprintf': This function or variable may be unsafe. Consider using snprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
To address this I have changed the instance of snprintf to sprintf_s.
Three errors in GUI.cpp, were instances of...
Error C4996 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
To address all of these I changed each instance of strcpy to strcpy_s.
And one error in GUI.cpp, this being an instance of...
error C4996 'snprintf': This function or variable may be unsafe. Consider using snprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
To address this I have changed the instance of snprintf to sprintf_s.
One error in Render.cpp, this being an instance of...
error C4996 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
To address this I have changed the instance of sprintf to sprintf_s.
Then build and it works:)
Thank you so much for your reply as I had moved on to other things but will find it very useful I think being able to build and run this demo.
It's only your reply that has brought me back to it and this time, I am successful:)

"Undefined variable: Environment" when editing SConscript file in Eclipse Neon

I have an SCons project (an implementation of the Generic Mapping Tools tutorial at http://gmt.soest.hawaii.edu/doc/latest/GMT_Tutorial.html using SCons rather than shell scripts), and I am using Eclipse Neon to edit the Sconstruct file.
The Sconstruct file starts in quite a standard way (the rest of the file is immaterial to this question).
import os
import collections
env = Environment(ENV = os.environ)
bld = Builder(action = 'ps2pdf $SOURCE $TARGET', \
suffix = '.pdf', \
src_suffix = '.ps')
What is annoying me is that while the build works perfectly using scons, Eclipse keeps marking the Environment and Builder constructions as "Undefined variables".
I installed the SConsolidator plugin, but it makes no difference.
I find the marking of an error that is not an error incredibly annoying.
While I could do something like tell Eclipse to ignore the error, I would prefer something more intelligent, such as adding Scons to the library path. I have tried adding C:\Python27\Lib\site-packages\scons-2.5.1\Scons and C:\Python27\Lib\site-packages\scons-2.5.1\Scons\Scripts to the Python Interpreter Paths (Window → Preferences → PyDev → Interpreters → Python Interpreters → Paths), and using an import directive like from SConscript.SCons import * but it doesn't make a difference.
Try library path:
C:\Python27\Lib\site-packages\scons-2.5.1\
Then
from SCons.Script import *
First thing first - if you know exactly where does your plugin keep it's symbol index(es) make sure that they don't get deleted by whatever the editor/IDE/build think they are doing to "be helpful".
Python plugins for editors easily get confused and you may need you to draw very explicit and detailed picture and train them a bit (by stopping the code in debugger) in order for a scanner/indexer to "wake up" and finally scan and index all symbols.
What I do in VS (with PTVS) is to make one proj for Scons_lib (home at C:\Python27\Lib\site-packages\scons-2.5.0), another for Scons_Scripts (C:\Python27\Scripts\, startup file: scons.py)
and then separate projects for separate scons driven folders/builds. To get editor to immediately recognize building files as Python I add extension .scons (google's convention used in Chrome build, Sconcsript's are ProjName.scons), tell VS that .scons is also Python, rename Sconstruct to Make.scons.
Then I run in debugger, (with -f Make.scons -n of course) as many times as I can :-) trying to place breakpoints in different files form different sub-packages that I know will run. Letting scons throw exceptions for nothing (like missing Sconstuct file) is also file - the goal is to force indexer to go places because it sees that debugger is going there.
After N runs, (and/or K days). PTVS (you can consider it a plugin) all of the sudden starts recognizing all symbols, packages, sub-packages, only can't penetrate things explicitly hidden behind caches.
Gave up trying to determine which events exactly make the scanner/indexer see the light. Probably something like seeing the number of files at "unexpected" paths being in debugger. Most symbols are visible in debugger immediately, except for the files that load first (scons.py and my own file that I exec from scons.py to inject whatever I want before anything else runs.)
Also I keep PYTHONDONTWRITEBYTECODE=1 to make sure that it always has to load actual .py-s
It might potentially help to have a single file that would exercise something form every sub-package, litter it with breakpoints and let it be run a few times.

Installing haxe

I have a problem with programming in Haxe. Whenever I try to run a code, I get an error:
Please don't add haxe/std to your classpath, instead set HAXE_STD_PATH env var.
I tried to find a solution - according to multiple sites, I'm supposed to change the environment variable HAXE_LIBRARY_PATH to HAXE_STD_PATH and set the value to actual path to the std file in my haxe folder. In my case, there was no such variable among my env vars, so I made HAXE_STD_PATH as a new one - and I still get the same error.
I'm using FlashDevelop and when I try to search for any class that would reference std, I can see in Type Explorer that there is a classpath that leads straight to haxe/std, which should not happen IMO. I looked at classpaths in Properties and the path to std was not listed, so I could not change it.
So problem could be in the classpath or in FlashDevelop settings.
Did anyone have the same problem?
Oh, and BTW I'm using Windows - and yes, restarting did not help.
I removed all: FD including program settings and HaxeToolkit (the whole map).
Then I reinstalled FD, Haxe (using the apps window from FD), Lime and openFL (from command window).
Now I don't get this error anymore.