Skip to content

Commit

Permalink
Add documentation for LSP with different IDEs (FuelLabs#4801)
Browse files Browse the repository at this point in the history
## Description

Closes FuelLabs#4276

Screenshots:

![Screenshot 2023-07-14 at 2 10 47
PM](https://github.com/FuelLabs/sway/assets/47993817/aa2bd354-98ed-4254-b69e-c1a8b38ffea6)
![Screenshot 2023-07-14 at 2 10 57
PM](https://github.com/FuelLabs/sway/assets/47993817/f565af29-3360-4c90-a4da-fa294c80b386)
![Screenshot 2023-07-14 at 2 11 02
PM](https://github.com/FuelLabs/sway/assets/47993817/6853fa8d-2595-4fd9-8510-7dae20dcff48)
![Screenshot 2023-07-14 at 2 11 12
PM](https://github.com/FuelLabs/sway/assets/47993817/6517793c-6fcf-4829-8c29-32fd4489e324)


## Checklist

- [x] I have linked to any relevant issues.
- [ ] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [ ] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [ ] I have requested a review from the relevant team or maintainers.

---------

Co-authored-by: Joshua Batty <[email protected]>
  • Loading branch information
sdankel and JoshuaBatty authored Jul 17, 2023
1 parent 55cb408 commit 6b50f9d
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 5 deletions.
3 changes: 3 additions & 0 deletions docs/book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
- [Testing with Rust](./testing/testing-with-rust.md)
- [Application Frontend](./frontend/index.md)
- [TypeScript SDK](./frontend/typescript_sdk.md)
- [Sway LSP](./lsp/index.md)
- [Installation](./lsp/installation.md)
- [Features](./lsp/features.md)
- [Sway Reference](./reference/index.md)
- [Compiler Intrinsics](./reference/compiler_intrinsics.md)
- [Attributes](./reference/attributes.md)
Expand Down
6 changes: 1 addition & 5 deletions docs/book/src/introduction/fuel_toolchain.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ The "Fuel Orchestrator" [Forc](https://github.com/FuelLabs/sway/tree/master/forc

## Sway Language Server (`forc-lsp`)

The Sway Language Server `forc-lsp` is provided to expose features to IDEs. [Installation instructions](./installation.md).

Currently, only [Visual Studio Code is supported through a plugin](https://marketplace.visualstudio.com/items?itemName=FuelLabs.sway-vscode-plugin). Vim support is forthcoming, though [syntax highlighting is provided](https://github.com/FuelLabs/sway.vim).

> **Note**: There is no need to manually run `forc-lsp` (the plugin will automatically start it), however both `forc` and `forc-lsp` must be in your `$PATH`. To check if `forc` is in your `$PATH`, type `forc --help` in your terminal.
The Sway Language Server `forc-lsp` is provided to expose features to IDEs. [Installation instructions](../lsp/installation.md).

## Sway Formatter (`forc-fmt`)

Expand Down
49 changes: 49 additions & 0 deletions docs/book/src/lsp/features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Features

## Code Actions

_Source:_ [code_actions](https://github.com/FuelLabs/sway/tree/master/sway-lsp/src/capabilities/code_actions)

Quickly generate boilerplate code and code comments for functions, structs, and ABIs.

## Completion

_Source:_ [completion.rs](https://github.com/FuelLabs/sway/blob/master/sway-lsp/src/capabilities/completion.rs)

Suggests code to follow partially written statements for functions and variables.

## Diagnostics

_Source:_ [diagnostic.rs](https://github.com/FuelLabs/sway/blob/master/sway-lsp/src/capabilities/diagnostic.rs)

Displays compiler warnings and errors inline.

## Syntax Highlighting

_Source:_ [highlight.rs](https://github.com/FuelLabs/sway/blob/master/sway-lsp/src/capabilities/highlight.rs)

Highlights code based on type and context.

## Hover

_Source:_ [hover](https://github.com/FuelLabs/sway/tree/master/sway-lsp/src/capabilities/hover)

Provides documentation, compiler diagnostics, and reference links when hovering over functions and variables.

## Inlay Hints

_Source:_ [inlay_hints.rs](https://github.com/FuelLabs/sway/blob/master/sway-lsp/src/capabilities/inlay_hints.rs)

Displays the implied type of a variable next to the variable name. Configurable in Settings.

## Rename

_Source:_ [rename.rs](https://github.com/FuelLabs/sway/blob/master/sway-lsp/src/capabilities/rename.rs)

Renames a symbol everywhere in the workspace.

## Run

_Source:_ [runnable.rs](https://github.com/FuelLabs/sway/blob/master/sway-lsp/src/capabilities/runnable.rs)

Shows a button above a runnable function or test.
14 changes: 14 additions & 0 deletions docs/book/src/lsp/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Sway LSP

Welcome to the documentation for Sway LSP, the language server designed specifically for the Sway programming language. This documentation serves as a comprehensive guide to help you understand and utilize the powerful features provided by Sway LSP.

Sway LSP is built on the [Language Server Protocol](https://microsoft.github.io/language-server-protocol/) (LSP), a standardized protocol for enabling rich programming language support in editor and IDE environments. It acts as a bridge between your favorite code editor or integrated development environment and the Sway programming language, offering advanced semantic analysis and a wide range of features to enhance your development experience.

With Sway LSP, you can expect a seamless and efficient coding experience while working with the Sway programming language. It provides intelligent code completion, precise symbol navigation, type information, and other smart features that empower you to write clean and error-free code. By leveraging the power of Sway LSP, you can increase productivity, reduce debugging time, and write high-quality code with confidence.

In this documentation, you will find detailed information about how to set up Sway LSP in your preferred code editor or IDE, configure its settings to match your coding style, and take advantage of its various features. We will guide you through the installation process, provide examples of typical configuration setups, and walk you through the usage of each feature supported by Sway LSP.

Whether you are a beginner or an experienced Sway developer, this documentation aims to be your go-to resource for understanding and maximizing the capabilities of Sway LSP. So let's dive in and unlock the full potential of the Sway programming language with Sway LSP!

- [Installation](./installation.md)
- [Features](./lsp/features.md)
27 changes: 27 additions & 0 deletions docs/book/src/lsp/installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Installation

The Sway language server is contained in the [forc-lsp](../forc/plugins/forc_lsp.md) binary, which is installed as part of the [Fuel toolchain](../introduction/fuel_toolchain.md). Once installed, it can be used with a variety of IDEs. It must be installed for any of the IDE plugins to work.

> **Note**: There is no need to manually run `forc-lsp` (the plugin will automatically start it), however both `forc` and `forc-lsp` must be in your `$PATH`. To check if `forc` is in your `$PATH`, type `forc --help` in your terminal.
## VS Code

This is the best supported editor at the moment.

You can install the latest release of the plugin from the [marketplace](https://marketplace.visualstudio.com/items?itemName=FuelLabs.sway-vscode-plugin).

Note that we only support the most recent version of VS Code.

## vim / neovim

Follow the documentation for [sway.vim](https://github.com/FuelLabs/sway.vim) to install.

## helix

[Install helix](https://docs.helix-editor.com/install.html) and Sway LSP will work out of the box.

Sway support is built into helix using [tree-sitter-sway](https://github.com/FuelLabs/tree-sitter-sway).

## Emacs

Coming soon! Feel free to [contribute](https://github.com/FuelLabs/sway/issues/3527).

0 comments on commit 6b50f9d

Please sign in to comment.