fsharp / emacs-fsharp-mode

F# Emacs mode
Apache License 2.0
206 stars 62 forks source link

FsAutoComplete (mono) raise an exception after first request #254

Open thomashilke opened 3 years ago

thomashilke commented 3 years ago

Description

When I run M-x eglot in a buffer where fsharp-mode is enabled, an zip archive containing the FsAutoComplete distribution files is downloaded and unpackaged into ~/.emacs.d/FsAutoComplete. Then eglot start the LSP server by running the equivalent of mono /home/.../.emacs.d/.emacs.d/FsAutoComplete/netframework/fsautocomplete.exe --background-service-enabled. This last command is returned by eglot-fsharp.

After the connection is established, the request

(:jsonrpc "2.0" :id 1 :method "initialize" :params
          (:processId 22044 :rootPath "/home/.../test/" :rootUri "file:///home/.../test/" :initializationOptions
                      (:automaticWorkspaceInit t)
                      :capabilities
                      (:workspace
                       (:applyEdit t :executeCommand
                                   (:dynamicRegistration :json-false)
                                   :workspaceEdit
                                   (:documentChanges :json-false)
                                   :didChangeWatchedFiles
                                   (:dynamicRegistration t)
                                   :symbol
                                   (:dynamicRegistration :json-false)
                                   :configuration t)
                       :textDocument
                       (:synchronization
                        (:dynamicRegistration :json-false :willSave t :willSaveWaitUntil t :didSave t)
                        :completion
                        (:dynamicRegistration :json-false :completionItem
                                              (:snippetSupport t)
                                              :contextSupport t)
                        :hover
                        (:dynamicRegistration :json-false :contentFormat
                                              ["markdown" "plaintext"])
                        :signatureHelp
                        (:dynamicRegistration :json-false :signatureInformation
                                              (:parameterInformation
                                               (:labelOffsetSupport t)))
                        :references
                        (:dynamicRegistration :json-false)
                        :definition
                        (:dynamicRegistration :json-false)
                        :declaration
                        (:dynamicRegistration :json-false)
                        :implementation
                        (:dynamicRegistration :json-false)
                        :typeDefinition
                        (:dynamicRegistration :json-false)
                        :documentSymbol
                        (:dynamicRegistration :json-false :symbolKind
                                              (:valueSet
                                               [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26]))
                        :documentHighlight
                        (:dynamicRegistration :json-false)
                        :codeAction
                        (:dynamicRegistration :json-false :codeActionLiteralSupport
                                              (:codeActionKind
                                               (:valueSet
                                                ["quickfix" "refactor" "refactor.extract" "refactor.inline" "refactor.rewrite" "source" "sour\
ce.organizeImports"])))
                        :formatting
                        (:dynamicRegistration :json-false)
                        :rangeFormatting
                        (:dynamicRegistration :json-false)
                        :rename
                        (:dynamicRegistration :json-false)
                        :publishDiagnostics
                        (:relatedInformation :json-false))
                       :experimental nil)))

is forwarded to the LSP server (as shown in the buffer *EGLOT (test/fsharp-mode) events*), and the server respond with the following error:

[server-reply] (id:1) ERROR Tue Nov 17 13:51:44 2020:
(:jsonrpc "2.0" :id 1 :error
          (:code -32603 :message "System.TypeInitializationException: The type initializer for
'Microsoft.Data.Sqlite.SqliteConnection' threw an exception. --->
System.Reflection.TargetInvocationException: Exception has been thrown
by the target of an invocation. ---> System.DllNotFoundException:
e_sqlite3 assembly:<unknown assembly> type:<unknown type>
member:(null)\n  at (wrapper managed-to-native)
SQLitePCL.SQLite3Provider_e_sqlite3+NativeMethods.sqlite3_libversion_number()\n
at
SQLitePCL.SQLite3Provider_e_sqlite3.SQLitePCL.ISQLite3Provider.sqlite3_libversion_number
() [0x00000] in <60b9636eddae467abf835d7bde5925d6>:0 \n  at
SQLitePCL.raw.SetProvider (SQLitePCL.ISQLite3Provider imp) [0x00008]
in <4a65135bb20943459d36511273e609dc>:0 \n  at
SQLitePCL.Batteries_V2.Init () [0x00005] in
<635106fb54074b6697e6f94014d8533a>:0 \n  at (wrapper
                                             managed-to-native)
System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)\n
at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj,
                                                             System.Reflection.BindingFlags
                                                             invokeAttr,
                                                             System.Reflection.Binder
                                                             binder,
                                                             System.Object[]
                                                             parameters,
                                                             System.Globalization.CultureInfo
                                                             culture)
[0x0007c] in <12b418a7818c4ca0893feeaaf67f1e7f>:0 \n   --- End of
inner exception stack trace ---\n  at
System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj,
                                                          System.Reflection.BindingFlags
                                                          invokeAttr,
                                                          System.Reflection.Binder
                                                          binder,
                                                          System.Object[]
                                                          parameters,
                                                          System.Globalization.CultureInfo
                                                          culture)
[0x0009a] in <12b418a7818c4ca0893feeaaf67f1e7f>:0 \n  at
System.Reflection.MethodBase.Invoke (System.Object obj,
                                                   System.Object[]
                                                   parameters)
[0x00000] in <12b418a7818c4ca0893feeaaf67f1e7f>:0 \n  at
Microsoft.Data.Sqlite.Utilities.BundleInitializer.Initialize ()
[0x0002f] in <b46e232ade014524baa458345f270c50>:0 \n  at
Microsoft.Data.Sqlite.SqliteConnection..cctor () [0x00000] in
<b46e232ade014524baa458345f270c50>:0 \n   --- End of inner exception
stack trace ---\n  at (wrapper managed-to-native)
System.Object.__icall_wrapper_mono_generic_class_init(intptr)\n  at
SymbolCache+PersistenCacheImpl.initializeCache (System.String dir)
[0x00049] in <56a19b898b41d0b0a931c1ad7999f115>:0 \n  at
FsAutoComplete.Commands`1[analyzer].StartBackgroundService
(Microsoft.FSharp.Core.FSharpOption`1[T] workspaceDir) [0x00016] in
<56a19b898b41d0b0a931c1ad7999f115>:0 \n  at
FsAutoComplete.Lsp+Initialize@422.Invoke (Microsoft.FSharp.Core.Unit
                                          unitVar) [0x00033] in
<c54a29a614138c8bdb825198c178886d>:0 \n  at
Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult]
(Microsoft.FSharp.Control.AsyncActivation`1[T] ctxt, TResult result1,
                                           Microsoft.FSharp.Core.FSharpFunc`2[T,TResult]
                                           part2) [0x00005] in
<039b17603f7a807e0eeaa652dc64c784>:0 \n  at
Microsoft.FSharp.Control.Trampoline.Execute
(Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] firstAction) [0x00020]
in <039b17603f7a807e0eeaa652dc64c784>:0 "))

(roughly reformatted for lisibility), and then the server crashes. Note that the foder ~/.emacs.d/FsAutoComplete/netframework/ contains e_sqlite3.dll, as well as SQLitePCLRaw.provider.e_sqlite3.dll.

Repro steps

  1. Given the relevent configuration in ~/.emacs.d/init.el given below, open a .fs file.

Expected behavior

FsAutoComplete.exe should start successfully, and not crash, failing to load a DLL related to e_sqlite3.dll.

Actual behavior

FsAutoComplete.exe raise an exception while handling the first json-rpc request it receive. Error message talks about System.DllNotFoundException: e_sqlite3. The error message fills the minibuffer.

Known workarounds

None that I know of.

Related information

juergenhoetzel commented 3 years ago

This is a known issue on Mono. I reported it upstream some time ago: https://github.com/fsharp/FsAutoComplete/issues/448

Mono is considered unsupported (for fsautocomplete). Upstream quote

FsAutoComplete can run on .NET/mono or .NET Core. We highly recommend using .Net Core version of FSAC as we plan to remove "full framework" version soon - read more

We should remove Mono support in eglot-fsharp to prevent starting a broken LSP-server in the first place.