Skip to content

Commit

Permalink
Move forc's LSP support into a dedicated forc-lsp plugin crate (F…
Browse files Browse the repository at this point in the history
…uelLabs#1179)

* Move `forc`'s LSP support into a dedicated `forc-lsp` plugin crate.

This creates a dedicated `forc-lsp` plugin crate. With `forc`'s new
plugin support, having this plugin installed and available via `PATH`
enables the original behaviour of starting the sway language server via
`forc lsp <args>`.

This also acts as a local test for `forc` plugin support and as a simple
example of how to implement a `forc` plugin.

The old `lsp` and `forc_lsp` modules have been removed from `forc` in
favour of this new `forc-lsp` plugin.

* Add forc-lsp plugin to CI git tag version check

* forc-lsp: sync to current `forc` version at 0.9.2

* fuel-lsp: Use `major.minor` for dep versions

* forc-lsp: local deps must be major.minor.patch for publishing
  • Loading branch information
mitchmindtree authored Apr 8, 2022
1 parent c70240a commit a121a43
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 41 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ jobs:
run: |
cargo install toml-cli
./.github/workflows/scripts/verify_tag.sh ${{ github.ref_name }} forc/Cargo.toml
./.github/workflows/scripts/verify_tag.sh ${{ github.ref_name }} forc-lsp/Cargo.toml
./.github/workflows/scripts/verify_tag.sh ${{ github.ref_name }} forc-pkg/Cargo.toml
./.github/workflows/scripts/verify_tag.sh ${{ github.ref_name }} forc-util/Cargo.toml
./.github/workflows/scripts/verify_tag.sh ${{ github.ref_name }} sway-core/Cargo.toml
Expand Down
11 changes: 10 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"docstrings",
"examples/build-all-examples",
"forc",
"forc-lsp",
"forc-pkg",
"forc-util",
"parser",
Expand Down
15 changes: 15 additions & 0 deletions forc-lsp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "forc-lsp"
version = "0.9.2"
authors = ["Fuel Labs <[email protected]>"]
edition = "2021"
homepage = "https://fuel.network/"
license = "Apache-2.0"
repository = "https://github.com/FuelLabs/sway"
description = "A simple `forc` plugin for starting the sway language server."

[dependencies]
anyhow = "1"
clap = { version = "3", features = ["derive"] }
sway-lsp = { version = "0.9.2", path = "../sway-lsp" }
tokio = { version = "1.8" }
27 changes: 27 additions & 0 deletions forc-lsp/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//! A simple `forc` plugin for starting the sway language server.
//!
//! Once installed and available via `PATH`, can be executed via `forc lsp`.
use clap::Parser;

#[derive(Debug, Parser)]
#[clap(
name = "forc-lsp",
about = "Forc plugin for the Sway LSP (Language Server Protocol) implementation.",
version
)]
pub struct App {
/// Instructs the client to draw squiggly lines under all of the tokens that our server managed
/// to parse.
#[clap(long)]
pub parsed_tokens_as_warnings: bool,
}

#[tokio::main]
async fn main() {
let app = App::parse();
let dbg = sway_lsp::utils::debug::DebugFlags {
parsed_tokens_as_warnings: app.parsed_tokens_as_warnings,
};
sway_lsp::start(dbg).await
}
1 change: 0 additions & 1 deletion forc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ serde = {version = "1.0", features = ["derive"]}
serde_json = "1.0.73"
sway-core = { version = "0.9.2", path = "../sway-core" }
sway-fmt = { version = "0.9.2", path = "../sway-fmt" }
sway-lsp = { version = "0.9.2", path = "../sway-lsp" }
sway-types = { version = "0.9.2", path = "../sway-types" }
sway-utils = { version = "0.9.2", path = "../sway-utils" }
taplo = "0.7"
Expand Down
19 changes: 0 additions & 19 deletions forc/src/cli/commands/lsp.rs

This file was deleted.

1 change: 0 additions & 1 deletion forc/src/cli/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub mod explorer;
pub mod format;
pub mod init;
pub mod json_abi;
pub mod lsp;
pub mod parse_bytecode;
pub mod run;
pub mod test;
Expand Down
7 changes: 2 additions & 5 deletions forc/src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use self::commands::{
addr2line, build, clean, completions, deploy, explorer, format, init, json_abi, lsp,
parse_bytecode, run, test, update,
addr2line, build, clean, completions, deploy, explorer, format, init, json_abi, parse_bytecode,
run, test, update,
};
use addr2line::Command as Addr2LineCommand;
use anyhow::{anyhow, Result};
Expand All @@ -13,7 +13,6 @@ pub use explorer::Command as ExplorerCommand;
pub use format::Command as FormatCommand;
pub use init::Command as InitCommand;
pub use json_abi::Command as JsonAbiCommand;
pub use lsp::Command as LspCommand;
use parse_bytecode::Command as ParseBytecodeCommand;
pub use run::Command as RunCommand;
use test::Command as TestCommand;
Expand Down Expand Up @@ -48,7 +47,6 @@ enum Forc {
Test(TestCommand),
Update(UpdateCommand),
JsonAbi(JsonAbiCommand),
Lsp(LspCommand),
/// This is a catch-all for unknown subcommands and their arguments.
///
/// When we receive an unknown subcommand, we check for a plugin exe named
Expand Down Expand Up @@ -77,7 +75,6 @@ pub async fn run_cli() -> Result<()> {
Forc::Test(command) => test::exec(command),
Forc::Update(command) => update::exec(command).await,
Forc::JsonAbi(command) => json_abi::exec(command),
Forc::Lsp(command) => lsp::exec(command).await,
Forc::Plugin(args) => {
let output = plugin::execute_external_subcommand(args)?;
let code = output
Expand Down
13 changes: 0 additions & 13 deletions forc/src/ops/forc_lsp.rs

This file was deleted.

1 change: 0 additions & 1 deletion forc/src/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ pub mod forc_deploy;
pub mod forc_explorer;
pub mod forc_fmt;
pub mod forc_init;
pub mod forc_lsp;
pub mod forc_run;
pub mod forc_update;

0 comments on commit a121a43

Please sign in to comment.