dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.85k stars 667 forks source link

OmniSharp fails to start if it reads an unparsesable sln file #2367

Open MK-Alias opened 6 years ago

MK-Alias commented 6 years ago

Environment data

.NET Command Line Tools (2.1.104)

Product Information:
 Version:            2.1.104
 Commit SHA-1 hash:  48ec687460

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17134
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.1.104\

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.6
  Build    : 74b1c703813c8910df5b96f304b0f2b78cdf194d

VS Code version: Version 1.23.1 Commit d0182c3417d225529c6d5ad24b7572815d0de9ac Date 2018-05-10T17:11:17.614Z Shell 1.7.12 Renderer 58.0.3029.110 Node 7.9.0 Architecture x64

C# Extension version: ? :S

Steps to reproduce

Make a project directory with some template sln/csproj (useless when not processed) files which are alphabetically before the real (processed template) sln/csproj files. For example:

<projectdir>/AAA/MyProject.template.sln
<projectdir>/BBB/MyProject.sln (this one is generated, the input is MyProject.template.sln)

Omnisharp will use the template instead of the real MyProject.sln file.

Expected behavior

A good working editor instead of only having basic syntax highlighting.

Actual behavior

Facilities like autocomplete does not work outside of the working file because omnisharp is using a template file - which does not contain any useful information - instead of the real Solution File. A workaround is to rename my templates so not to use the SNL or CSPROJ extension. For example rename: MyProject.template.sln -> MyProject.sln.template. In which case omnisharp will ignore the file. I've seen other languages make use of choosing a project/xml/sln file from the editor which will be used. Something like that would be pretty nice!

Obliviously this is a very minor issue, especially if you know that renaming the templates will solve it. Just wanted to make a note of it!

rchande commented 6 years ago

@Alias-777 What version of the C# extension are you on? You wrote ? :S in your issue. Once you install the latest version, you should be able to click on the folder icon next to the green flame and select any solution you want: image

MK-Alias commented 6 years ago

I wrote ? because the name "omnisharp" was in my mind, because of constantly seeing this word in the output console. I didn't really know what was being referred. Sorry! :D. But i'm using 1.15.2 . and I always update.

There was no folder icon next to the green flame when It was using the template. Perhaps the parser that parses the SNL files gave up because of the macro code (al lot of ${VARS} that are parsed by my template engine) inside does not make any sense to it. As soon as I changed the extension from SLN to .template the folder showed up after restarting vscode and everything worked as expected.

I'm was using the SNL extension in a non-valid way, which is most likely part of the problem, because of unexpected syntax. The only real problem was not being able the choose a sln (next to the green fire).

Edit: Also the paths to the source-code of the templates is non-valid. It only becomes valid after parsing it.

rchande commented 6 years ago

More concrete repro: use dotnet to create a csproj and 2 solutions, a.sln and b.sln. Add the csproj to b. Edit a to contain a parse error. Open VS Code in that folder. OmniSharp will fail to start and won't show the folder icon because something goes wrong when it attempts to read a. Renaming a to c.sln allows omnisharp to load.

rchande commented 6 years ago

Thanks @Alias-777 for filing this interesting issue. @akshita31 I've assigned it to you to take a look. Presumably this is going to require changes to omnisharp to fix.

MK-Alias commented 6 years ago

@rchande that repro looks more objective then mine! The main problem seems to be after failing on A it does not analyze and use B anymore. If A = C then it fails but already has analyzed B and uses that one. Again this is a minor issue, but still would be nice if it can be fixed somehow.

Thanks!

DustinCampbell commented 6 years ago

Even if the folder doesn't appear on the icon, you should be able to invoke the 'OmniSharp : Select Project' command in VS Code to pick the correct solution.

vramanx commented 6 years ago

Along the same lines: how do i set a default sln to use when i point to a folder with multiple slns?

rchande commented 6 years ago

@vramanx @janaka is working on a PR to contribute that functionality: https://github.com/OmniSharp/omnisharp-vscode/pull/2053