qsharp-compiler
qsharp-compiler copied to clipboard
Clicking between operation name and parens crashes language server
Describe the bug
Q# Language server crashes when clicking in a particular place in the file
To Reproduce
Steps to reproduce the behavior:
- Create a Q# file with the following contents and open in VSCode with with the Quantum SDK extension installed:
namespace helloworld {
operation yes(x: Bool): Bool {
return not x;
}
operation bob(): Unit {
yes()
}
}
- Click between
yesand()on line 7. (That is, click such that your cursor is betweenyesand()on the line insidebob()) - You should get a popup saying "The Q# Language Server has encountered an error. Diagnostics will be reloaded upon saving the file. Details on the encountered error have been logged to the output window." The output window has the following stack trace:
System.InvalidOperationException: Sequence contains more than one matching element
at System.Linq.ThrowHelper.ThrowMoreThanOneMatchException()
at System.Linq.Enumerable.TryGetSingle[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
at Microsoft.Quantum.QsCompiler.CompilationBuilder.SymbolInfo.SymbolOccurrence(CodeFragment fragment, Position position, Boolean includeEnd) in C:\Users\t-aadams\Documents\qsharp-compiler\src\QsCompiler\CompilationManager\EditorSupport\SymbolInfo.cs:line 88
at Microsoft.Quantum.QsCompiler.CompilationBuilder.SymbolInfo.TryGetReferences(FileContentManager file, CompilationUnit compilation, Position position, Location& declarationLocation, IEnumerable`1& referenceLocations, IImmutableSet`1 limitToSourceFiles) in C:\Users\t-aadams\Documents\qsharp-compiler\src\QsCompiler\CompilationManager\EditorSupport\SymbolInfo.cs:line 195
at Microsoft.Quantum.QsCompiler.CompilationBuilder.EditorCommands.DocumentHighlights(FileContentManager file, CompilationUnit compilation, Position position) in C:\Users\t-aadams\Documents\qsharp-compiler\src\QsCompiler\CompilationManager\EditorSupport\EditorCommands.cs:line 192
at Microsoft.Quantum.QsCompiler.CompilationBuilder.ProjectManager.<>c__DisplayClass24_0.<DocumentHighlights>b__0(FileContentManager file, CompilationUnit c) in C:\Users\t-aadams\Documents\qsharp-compiler\src\QsCompiler\CompilationManager\ProjectManager.cs:line 1236
at Microsoft.Quantum.QsCompiler.CompilationBuilder.CompilationUnitManager.<FileQuery>g__TryQueryFile|46_0[T](FileContentManager f, <>c__DisplayClass46_0`1& ) in C:\Users\t-aadams\Documents\qsharp-compiler\src\QsCompiler\CompilationManager\CompilationUnitManager.cs:line 887
The more information you can provide, the more likely someone will be successful at reproducing the issue and finding a fix.
Expected behavior
I can absent-mindedly click around the file without the language server crashing
System information
- Quantum Devkit for VSCode v0.25.218240 with
quantumDevKit.languageServerPathset to a fresh language server built against 241fa7d4aa47f7df1e6 (mainat the moment) - Windows 11 with .NET runtime 6.0.7 and .NET 6.0.302
- VSCode 1.69.2
I can reproduce this on a local instance of Azure Notebooks as well, which is where I originally found the issue