dfinity / vscode-motoko

Motoko language support for VS Code.
Apache License 2.0
42 stars 16 forks source link

Add "Import Mops Package..." command #244

Closed ZenVoich closed 1 year ago

ZenVoich commented 1 year ago

Search, install and import packages from Mops.

image

v

image

After package select, adds package to mops.toml. If active file is *.mo - adds import line.


Also now new package import added after the latest import of the same package, or after latest "mo:..." import.

For example:

import Array "mo:base/Array";
import Local "./local";

add Map import from map package:

import Array "mo:base/Array";
+import Map "mo:map/Map";
import Local "./local";

add Trie import from base package:

import Array "mo:base/Array";
+import Trie "mo:base/Trie";
import Map "mo:map/Map";
import Local "./local";
rvanasa commented 1 year ago

This is awesome! Thank you for the contribution!

rvanasa commented 1 year ago

After some further testing, I've noticed that mopsAdd() sometimes doesn't add the package to the mops.toml config, although the package is installed in the .mops directory as expected. Based on the extension logs, this seems to be caused by the language server crashing (unfortunately without a readable error message).

I'll let you know if I come across any other useful debugging information, and thanks again for this PR!