drift icon indicating copy to clipboard operation
drift copied to clipboard

IDE not working in VS Code

Open kansson opened this issue 4 years ago • 26 comments

The experimental IDE is not working in VS Code using the configuration in the docs. The moor files are detected as plain text files.

Vs Code version: 1.61.0 using WSL2

analysis_options.yaml

include: package:lint/analysis_options.yaml
analyzer:
  plugins:
    - moor

settings.json

{
    "workbench.colorTheme": "Nord",
    "editor.formatOnSave": true,
    "dart.additionalAnalyzerFileExtensions": [
        "moor"
    ],
    "[dart]": {
        "editor.selectionHighlight": false,
        "editor.suggest.snippetsPreventQuickSuggestions": false,
        "editor.suggestSelection": "first",
        "editor.tabCompletion": "onlySnippets",
        "editor.wordBasedSuggestions": false,
        "editor.codeActionsOnSave": {
            "source.organizeImports": true,
        },
    },
    "editor.bracketPairColorization.enabled": true
}

kansson avatar Oct 10 '21 19:10 kansson

Thanks for the report! I'm able to reproduce this locally and I see that the problem is. This will be fixed by the next update, which I'm aiming to release this week.

simolus3 avatar Oct 11 '21 08:10 simolus3

Thank you for looking into it 😄

kansson avatar Oct 11 '21 13:10 kansson

Was this fixed in the latest moor (or drift) release?

kansson avatar Oct 13 '21 05:10 kansson

It should work if you migrate to drift. You also need to replace moor with drift in your analysis_options.yaml, something that I overlooked in the moor_generator migrate command.

I made a mistake while moving the plugin code over to the new package, so unfortunately it still doesn't work with moor 4.6.0 alone. I'll release a 4.6.1 version to fix the moor plugin and the migrate command later today.

simolus3 avatar Oct 13 '21 09:10 simolus3

It does not work, maybe I'm doing something wrong. There is no auto completion or syntax highlighting in .drift files.

VS Code 1.61.0 inside of WSL2. Dart SDK 2.14.3 (stable) on "linux_x64". Dart VS Code extension v3.27.2.

dependencies:
  drift: ^1.0.1
  sqlite3_flutter_libs: ^0.5.1

dev_dependencies:
  build_runner: ^2.1.4
  drift_dev: ^1.0.1
include: package:lint/analysis_options.yaml
analyzer:
  plugins:
    - drift
{
  "editor.formatOnSave": true,
  "dart.additionalAnalyzerFileExtensions": ["drift"],
  "[dart]": {
    "editor.selectionHighlight": false,
    "editor.suggest.snippetsPreventQuickSuggestions": false,
    "editor.suggestSelection": "first",
    "editor.tabCompletion": "onlySnippets",
    "editor.wordBasedSuggestions": false,
    "editor.codeActionsOnSave": {
      "source.organizeImports": true
    }
  }
}

kansson avatar Oct 13 '21 10:10 kansson

I just tried it with a new project and at least it looks like basic auto-completion and errors work with drift. Outline and highlighting appear to be broken, but that looks like another issue.

In your VS Code preferences, can you set "dart.analyzerDiagnosticsPort": 4040, and then restart the server (Ctrl-Shift-P, Dart: Restart analysis server). Does the plugin then show up at http://localhost:4040/plugins? What is the status being reported? (If it's saying "not running for an unknown reason" you probably just need to wait for a while). If there's an exception begin reported on that page it would be good to know though.

simolus3 avatar Oct 13 '21 18:10 simolus3

This is the output in the diagnostics page. https://imgur.com/a/LLeMR2Y

kansson avatar Oct 13 '21 19:10 kansson

Huh, so the plugin does get registered. If your moor/drift files have syntax errors, do they show up in the problems view and in the file? Are you using the LSP variant ("dart.previewLsp": true, the diagnostic site should also tell you this)?

simolus3 avatar Oct 13 '21 19:10 simolus3

Yes I'm using dart.previewLsp and there is no errors or anything in this example.

table.drift

CREATEsdfsdf TABLEasd todos (
    id INT NOT NULL PRIMARY KEY AUTOINCREMENT,
    title TEXT NOT NULL,
    content TEXT NOT NULL,
    category INTEGER REFERENCES categories(id)
);

kansson avatar Oct 13 '21 20:10 kansson

Hello @simolus3 do you have any update on this? Asking because this feature is cool and wan't to use it.

kansson avatar Oct 17 '21 20:10 kansson

Sorry, nothing new yet. I still couldn't reproduce this in its entirety (some IDE features work for me). Does it work for you if you create a new empty project with the plugin applied? That's what I used to test this.

simolus3 avatar Oct 17 '21 20:10 simolus3

Unfortunately, nothing works as expected with a new empty project.

kansson avatar Oct 19 '21 14:10 kansson

If you clear the local plugin cache (~/.dartServer/.plugin_manager or %LOCALAPPDATA%\.dartServer\.plugin_manager on Windows), does that help at all?

Otherwise I'll setup an example project for you to try out and I'll probably need the detailed diagnistic logs from there - it's hard to say what's going wrong here exactly.

simolus3 avatar Oct 19 '21 14:10 simolus3

I have the same issue here, It works only with .moor files and only when I run flutter pub run drift_dev analyze

MahmoodAliL avatar Oct 30 '21 05:10 MahmoodAliL

Also no luck with .drift Haven't tried .moor files yet I'm not seeing the analyzer in analysis server either Here is the repo - note that it's a mono repo, and the part that drift is in is self standing and pretty small. Here's the drift folder

When I have a chance, maybe I'll try setting up in a clean, never moored environment and see what happens Note I tried deleting the .dart_tool and .dartServer folders with vscode shut down and reopened it and ran pub get

Server type: LspAnalysisServer
Analysis server version: 1.32.7
Dart SDK: 2.14.4 (stable) (Wed Oct 13 11:11:32 2021 +0200) on "linux_x64"

I am getting an error trying to see lsp_capabilities, IDK what this is all about

[lsp](http://localhost:4040/lsp_capabilities) error
500 Oops

Converting object to an encodable object failed: LinkedHashSet len:22

#0      _JsonStringifier.writeObject (dart:convert/json.dart:688:7)
#1      _JsonStringStringifier.printOn (dart:convert/json.dart:877:17)
#2      _JsonStringStringifier.stringify (dart:convert/json.dart:862:5)
#3      JsonEncoder.convert (dart:convert/json.dart:262:30)
#4      Page.prettyJson.<anonymous closure> (package:analysis_server/src/status/pages.dart:124:29)
#5      Page.pre (package:analysis_server/src/status/pages.dart:117:8)
#6      Page.prettyJson (package:analysis_server/src/status/pages.dart:123:5)
#7      LspCapabilitiesPage.generateContent (package:analysis_server/src/status/diagnostics.dart:997:5)
#8      DiagnosticPageWithNav.generateContainer.<anonymous closure> (package:analysis_server/src/status/diagnostics.dart:743:13)
#9      DiagnosticPageWithNav.generateContainer.<anonymous closure> (package:analysis_server/src/status/diagnostics.dart:741:20)
#10     Page.asyncDiv (package:analysis_server/src/status/pages.dart:41:15)
#11     DiagnosticPageWithNav.generateContainer (package:analysis_server/src/status/diagnostics.dart:741:11)
#12     DiagnosticPage.generatePage (package:analysis_server/src/status/diagnostics.dart:697:11)
#13     Page.generate (package:analysis_server/src/status/pages.dart:63:12)
#14     Site.handleGetRequest (package:analysis_server/src/status/pages.dart:165:37)
#15     HttpAnalysisServer._handleGetRequest (package:analysis_server/src/server/http_server.dart:88:24)
#16     HttpAnalysisServer._handleServer.<anonymous closure> (package:analysis_server/src/server/http_server.dart:96:15)
#17     HttpAnalysisServer._handleServer.<anonymous closure> (package:analysis_server/src/server/http_server.dart:93:23)
#18     _RootZone.runUnaryGuarded (dart:async/zone.dart:1620:10)
#19     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#20     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#21     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:733:19)
#22     _StreamController._add (dart:async/stream_controller.dart:607:7)
#23     _StreamController.add (dart:async/stream_controller.dart:554:5)
#24     _HttpServer._handleRequest (dart:_http/http_impl.dart:3237:19)
#25     new _HttpConnection.<anonymous closure> (dart:_http/http_impl.dart:2990:19)
#26     _RootZone.runUnaryGuarded (dart:async/zone.dart:1620:10)
#27     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#28     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#29     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:733:19)
#30     _StreamController._add (dart:async/stream_controller.dart:607:7)
#31     _StreamController.add (dart:async/stream_controller.dart:554:5)
#32     _HttpParser._headersEnd (dart:_http/http_parser.dart:394:19)
#33     _HttpParser._doParse (dart:_http/http_parser.dart:750:15)
#34     _HttpParser._parse (dart:_http/http_parser.dart:324:7)
#35     _HttpParser._onData (dart:_http/http_parser.dart:878:5)
#36     _RootZone.runUnaryGuarded (dart:async/zone.dart:1620:10)
#37     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#38     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#39     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:733:19)
#40     _StreamController._add (dart:async/stream_controller.dart:607:7)
#41     _StreamController.add (dart:async/stream_controller.dart:554:5)
#42     _Socket._onData (dart:io-patch/socket_patch.dart:2166:41)
#43     _RootZone.runUnaryGuarded (dart:async/zone.dart:1620:10)
#44     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#45     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#46     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:733:19)
#47     _StreamController._add (dart:async/stream_controller.dart:607:7)
#48     _StreamController.add (dart:async/stream_controller.dart:554:5)
#49     new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1702:33)
#50     _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:1213:14)
#51     _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
#52     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
#53     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:120:13)
#54     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:185:5)

yringler avatar Nov 16 '21 14:11 yringler

I am getting an error trying to see lsp_capabilities, IDK what this is all about

I think I have fixed that in https://dart-review.googlesource.com/c/sdk/+/216186, but it's not in a stable SDK yet. It should be unrelated to this problem though, I'll check out your repo tomorrow (thanks for providing it!).

simolus3 avatar Nov 16 '21 15:11 simolus3

I'll check out your repo tomorrow (thanks for providing it!).

Great! And no problem. Fear not opensource, that's my motto. Using the .drift for some more complex joins, but my SQL chops are such that I could use all the hand holding I can get. In the meantime I'm using the dart API to do a simple join

yringler avatar Nov 16 '21 15:11 yringler

I had a quick look and it seems like the analyzer is just not picking up plugins at all now. If you navigate to /plugins on the diagnostics page, do you see anything?

I tried some print-debugging in the analyzer and the server, but I'm still mostly clueless. I'll try again tomorrow and open an issue on the SDK if I know it's an analyzer thing.

simolus3 avatar Nov 16 '21 18:11 simolus3

I had a quick look and it seems like the analyzer is just not picking up plugins at all now. If you navigate to /plugins on the diagnostics page, do you see anything?

Nope

No known analysis plugins. 

yringler avatar Nov 18 '21 02:11 yringler

Any update on this? Opened a bug on the SDK?

yringler avatar Nov 24 '21 15:11 yringler

It looks like the analyzer isn't recognizing drift, but it does recognize built_value_generator as a plugin for instance. I'll have to take another deeper look at this.

simolus3 avatar Nov 24 '21 17:11 simolus3

Any update on this? I actually used a drift file recently. The errors when I ran build were very useful, but design time etc is of course much more pleasant.

yringler avatar Jan 24 '22 15:01 yringler

So the good news is that I managed to get the plugin running again with the latest Dart SDK and Flutter 2.8.1. I fixed the bug causing only .moor files to be analyzed in 7d56497c184e278d9071d5968580815e7b606053. Still, it seems like not all IDE features are working with the plugin. I think this is due to the Dart analysis server rewriting some file locations now, but I couldn't reliably debug the analysis server to figure out where exactly it's going wrong.

simolus3 avatar Jan 24 '22 16:01 simolus3

Hi @simolus3. Has something changed? The IDE suddenly started working for me perfectly.

purplenoodlesoop avatar May 10 '22 19:05 purplenoodlesoop

Wait even syntax highlighting? I could never figure out how to get that back working :D I can take another look, perhaps something with the analysis server changed that it's now picking up plugins again?

simolus3 avatar May 12 '22 19:05 simolus3

Yep, even syntax highlighting :)

purplenoodlesoop avatar May 21 '22 15:05 purplenoodlesoop