dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.88k stars 677 forks source link

[O# Parity] Support dotnet script (.csx) files #6411

Open amine-aboufirass opened 1 year ago

amine-aboufirass commented 1 year ago

Type: Bug

Issue Description

Steps to Reproduce

  1. Create folder md scripting
  2. Navigate to the folder cd scripting
  3. Create a scripting project dotnet script init
  4. Add a file bye.csx
  5. Add some code into this file, e.g. Console.WriteLine("test");

Expected Behavior

The syntax highlighting works for file bye.csv

Actual Behavior

Using dotnet configured on PATH
Dotnet path: C:\Program Files\dotnet\dotnet.exe
Activating C# + C# Dev Kit + C# IntelliCode...
[Info  - 4:07:33 PM] [Program]Language server initialized
[Error - 4:07:50 PM] [LanguageServerHost]System.InvalidOperationException: Unexpected false - line 68
   at Roslyn.Utilities.Contract.Fail(String message, Int32 lineNumber) in /_/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/Contract.cs:line 154
   at Microsoft.CodeAnalysis.CSharp.SignatureHelp.InvocationExpressionSignatureHelpProviderBase.GetAccessibleMethods(InvocationExpressionSyntax invocationExpression, SemanticModel semanticModel, ISymbol within, IEnumerable`1 methodGroup, CancellationToken cancellationToken) in /_/src/Features/CSharp/Portable/SignatureHelp/InvocationExpressionSignatureHelpProviderBase_MethodGroup.cs:line 68
   at Microsoft.CodeAnalysis.CSharp.SignatureHelp.InvocationExpressionSignatureHelpProviderBase.GetItemsWorkerAsync(Document document, Int32 position, SignatureHelpTriggerInfo triggerInfo, SignatureHelpOptions options, CancellationToken cancellationToken) in /_/src/Features/CSharp/Portable/SignatureHelp/InvocationExpressionSignatureHelpProvider.cs:line 98
   at Microsoft.CodeAnalysis.SignatureHelp.AbstractSignatureHelpProvider.GetItemsAsync(Document document, Int32 position, SignatureHelpTriggerInfo triggerInfo, SignatureHelpOptions options, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/SignatureHelp/AbstractSignatureHelpProvider.cs:line 245
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SignatureHelpHandler.HandleRequestAsync(TextDocumentPositionParams request, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SignatureHelp/SignatureHelpHandler.cs:line 58
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken)
[Error - 4:07:50 PM] Request textDocument/signatureHelp failed.
  Message: Unexpected false - line 68
  Code: -32000 
[object Object]
Using dotnet configured on PATH

Logs

C# log

Post the output from Output-->C# here

C# LSP Trace Logs

Post the output from Output-->C# LSP Trace Logs here. Requires `dotnet.server.trace` to be set to `Trace`

Environment information

VSCode version: 1.82.2 C# Extension: 2.1.2 Using OmniSharp: false

Dotnet Information Error running dotnet --info: Error: Command failed: C:\Program Files\dotnet\dotnet.exe --info 'C:\Program' is not recognized as an internal or external command, operable program or batch file. 'C:\Program' is not recognized as an internal or external command, operable program or batch file.
Visual Studio Code Extensions |Extension|Author|Version|Folder Name| |---|---|---|---| |csdevkit|ms-dotnettools|0.4.10|ms-dotnettools.csdevkit-0.4.10-win32-x64| |csharp|ms-dotnettools|2.1.2|ms-dotnettools.csharp-2.1.2-win32-x64| |dotnet-interactive-vscode|ms-dotnettools|1.0.4461040|ms-dotnettools.dotnet-interactive-vscode-1.0.4461040| |jupyter|ms-toolsai|2023.8.1002501831|ms-toolsai.jupyter-2023.8.1002501831-win32-x64| |jupyter-keymap|ms-toolsai|1.1.2|ms-toolsai.jupyter-keymap-1.1.2| |jupyter-renderers|ms-toolsai|1.0.17|ms-toolsai.jupyter-renderers-1.0.17| |LiveServer|ritwickdey|5.7.9|ritwickdey.liveserver-5.7.9| |msbuild-project-tools|tintoy|0.4.9|tintoy.msbuild-project-tools-0.4.9| |pdf|tomoki1207|1.2.2|tomoki1207.pdf-1.2.2| |powershell|ms-vscode|2023.6.0|ms-vscode.powershell-2023.6.0| |python|ms-python|2023.16.0|ms-python.python-2023.16.0| |run-on-save|pucelle|1.6.0|pucelle.run-on-save-1.6.0| |vscode-dotnet-pack|ms-dotnettools|1.0.12|ms-dotnettools.vscode-dotnet-pack-1.0.12| |vscode-dotnet-runtime|ms-dotnettools|1.7.3|ms-dotnettools.vscode-dotnet-runtime-1.7.3| |vscode-jupyter-cell-tags|ms-toolsai|0.1.8|ms-toolsai.vscode-jupyter-cell-tags-0.1.8| |vscode-jupyter-slideshow|ms-toolsai|0.1.5|ms-toolsai.vscode-jupyter-slideshow-0.1.5| |vscode-pylance|ms-python|2023.9.20|ms-python.vscode-pylance-2023.9.20| |vscodeintellicode-csharp|ms-dotnettools|0.1.26|ms-dotnettools.vscodeintellicode-csharp-0.1.26-win32-x64|;

Extension version: 2.1.2 VS Code version: Code 1.82.2 (abd2f3db4bdb28f9e95536dfa84d8479f1eb312d, 2023-09-14T05:55:25.390Z) OS version: Windows_NT x64 10.0.19044 Modes:

System Info |Item|Value| |---|---| |CPUs|11th Gen Intel(R) Core(TM) i9-11950H @ 2.60GHz (16 x 2611)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled| |Load (avg)|undefined| |Memory (System)|63.67GB (48.67GB free)| |Process Argv|. --crash-reporter-id 9b73ea97-bda1-4db3-9fce-24ce43b1d8af| |Screen Reader|no| |VM|0%|
A/B Experiments ``` vsliv368cf:30146710 vsreu685:30147344 python383cf:30185419 vspor879:30202332 vspor708:30202333 vspor363:30204092 vslsvsres303:30308271 vserr242:30382549 pythontb:30283811 vsjup518:30340749 pythonptprofiler:30281270 vshan820:30294714 vstes263:30335439 vscorecescf:30445987 vscod805cf:30301675 binariesv615:30325510 bridge0708:30335490 bridge0723:30353136 vsaa593:30376534 pythonvs932:30410667 py29gd2263cf:30792227 vscaat:30438848 vsclangdc:30486549 c4g48928:30535728 dsvsc012cf:30540253 pynewext54:30695312 azure-dev_surveyone:30548225 2e4cg342:30602488 89544117:30613380 a9j8j154:30646983 showlangstatbar:30737416 03d35959:30757346 pythonfmttext:30731395 fixshowwlkth:30771522 showindicator:30805244 pythongtdpath:30769146 i26e3531:30792625 pythonnosmt12:30797651 pythonidxpt:30805730 pythonnoceb:30805159 copilotsettingc:30839828 dsvsc013:30795093 dsvsc014:30804076 diffeditorv2:30821572 dsvsc015:30829745 ```
bowtiedgnome commented 1 year ago

Ran into this issue tonight.

I had to add the following change to vscode settings

{
    "dotnet.server.useOmnisharp": true
}

Then I disabled the Dev Kit extension for a specific workspace where I'm writing dotnet script files. Doing this only affects that workspace and leaves the DevKit extension enabled globally for other workspaces where I'm writing typical libs or apps.

Once I disable the extension and reloaded vscode, it downloaded omnisharp. Then I had to reload vscode and restart the omnisharp server to get intellisense working.

Ideally it shouldn't require any configuration on the user's part to use dotnet script, but the above seems to work for now.

dibarbet commented 1 year ago

CSX support is still missing from the new server, for now the workaround is to set dotnet.server.useOmnisharp to true as mentioned above.

1m188 commented 10 months ago

I'm having a similar issue as well, and the above workaround does work. However, the resulting inconsistencies in the configuration behavior of the global project are unacceptable, and it is hoped that the configuration behavior of the script mode and the development mode can be unified.

hammypants commented 2 months ago

Can the Omnisharp commands be re-added, notably when useOmnisharp is true?

juwens commented 2 months ago

Another possible partial-workaround (if you don't want to disable devkit):

adding any #r enables parts of the intellisense with c# dev kit for me in csx.

I added #r "System" for example, and immediately all classes are recognized.

image

Omnisharp is not installed in vscode, nor anywhere else.

Some intellisense Stuff works:

image

Quite a few things don't work at all:

image

Version: 1.93.1 (user setup)
Commit: 38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40
Date: 2024-09-11T17:20:05.685Z
Electron: 30.4.0
ElectronBuildId: 10073054
Chromium: 124.0.6367.243
Node.js: 20.15.1
V8: 12.4.254.20-electron.0
OS: Windows_NT x64 10.0.19045

Name: C# Dev Kit
Id: ms-dotnettools.csdevkit
Description: Official C# extension from Microsoft
Version: 1.10.18
Publisher: Microsoft
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csdevkit

> code --list-extensions

albymor.increment-selection
alefragnani.project-manager
anweber.vscode-httpyac
asciidoctor.asciidoctor-vscode
bierner.markdown-mermaid
christianalexander.flip
clemenspeters.format-json
codezombiech.gitignore
cschlosser.doxdocgen
donjayamanne.git-extension-pack
donjayamanne.githistory
dotjoshjohnson.xml
eamodio.gitlens
eridem.vscode-nupkg
felipecaputo.git-project-manager
hbenl.vscode-mocha-test-adapter
hbenl.vscode-test-explorer
heaths.vscode-guid
in4margaret.compareit
kevinrose.vsc-python-indent
mechatroner.rainbow-csv
mrmlnc.vscode-json5
ms-dotnettools.csdevkit
ms-dotnettools.csharp
ms-dotnettools.dotnet-maui
ms-dotnettools.vscode-dotnet-runtime
ms-dotnettools.vscodeintellicode-csharp
ms-python.debugpy
ms-python.python
ms-python.vscode-pylance
ms-vscode-remote.remote-containers
ms-vscode.cpptools
ms-vscode.hexeditor
ms-vscode.powershell
ms-vscode.test-adapter-converter
nhoizey.gremlins
numso.prettier-standard-vscode
oliversturm.fix-json
redhat.vscode-xml
redhat.vscode-yaml
rust-lang.rust-analyzer
searking.preview-vscode
shd101wyy.markdown-preview-enhanced
sleistner.vscode-fileutils
streetsidesoftware.code-spell-checker
streetsidesoftware.code-spell-checker-german
streetsidesoftware.hunspell
tamasfe.even-better-toml
tintoy.msbuild-project-tools
waderyan.gitblame
ziyasal.vscode-open-in-github
zxh404.vscode-proto3

Without "#r" not intellisense

image

colinfang commented 2 months ago

@juwens

Do you know where I can find a bit more information on the usage of #r? Is this a new annotation syntax for C# compiler or is it brought in by this extension only?

juwens commented 2 months ago

@juwens

Do you know where I can find a bit more information on the usage of #r? Is this a new annotation syntax for C# compiler or is it brought in by this extension only?

It's used to load DLLs.

It's documented here and there as a side-note.

You'll find more by googling these searchwords https://www.google.com/search?q=c%23+script+%22r%23%22+directive