Skip to content

Commit

Permalink
Bump tower-lsp and use the lsp_types crate directly (FuelLabs#4657)
Browse files Browse the repository at this point in the history
## Description
Currently we have been using lsp_types through tower-lsp. 

We are going to be deprecating using tower-lsp soon and will instead
need to use the lsp_types crate directly. This PR removes importing
lsp_types through tower-lsp to achieve this.
  • Loading branch information
JoshuaBatty authored Jun 13, 2023
1 parent 060f276 commit c9175cb
Show file tree
Hide file tree
Showing 39 changed files with 63 additions and 67 deletions.
13 changes: 7 additions & 6 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion sway-lsp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ anyhow = "1.0.41"
dashmap = "5.4"
forc-pkg = { version = "0.40.1", path = "../forc-pkg" }
forc-tracing = { version = "0.40.1", path = "../forc-tracing" }
lsp-types = { version = "0.94", features = ["proposed"] }
notify = "5.0.0"
notify-debouncer-mini = { version = "0.2.0" }
parking_lot = "0.12.1"
Expand All @@ -33,7 +34,7 @@ tempfile = "3"
thiserror = "1.0.30"
tokio = { version = "1.3", features = ["io-std", "io-util", "macros", "net", "rt-multi-thread", "sync", "time"] }
toml_edit = "0.19"
tower-lsp = { version = "0.18", features = ["proposed"] }
tower-lsp = { version = "0.19", features = ["proposed"] }
tracing = "0.1"
urlencoding = "2.1.2"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use lsp_types::{Range, Url};
use sway_core::{
language::ty::{self, TyAbiDecl, TyFunctionParameter, TyTraitFn},
Engines,
};
use tower_lsp::lsp_types::{Range, Url};

use crate::capabilities::code_actions::{
common::generate_impl::{GenerateImplCodeAction, CONTRACT},
Expand Down
6 changes: 2 additions & 4 deletions sway-lsp/src/capabilities/code_actions/abi_decl/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
pub(crate) mod abi_impl;

use sway_core::{decl_engine::id::DeclId, language::ty::TyAbiDecl};
use tower_lsp::lsp_types::CodeActionOrCommand;

use self::abi_impl::AbiImplCodeAction;

use super::{CodeAction, CodeActionContext};
use lsp_types::CodeActionOrCommand;
use sway_core::{decl_engine::id::DeclId, language::ty::TyAbiDecl};

pub(crate) fn code_actions(
decl_id: &DeclId<TyAbiDecl>,
Expand Down
5 changes: 2 additions & 3 deletions sway-lsp/src/capabilities/code_actions/common/generate_doc.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::capabilities::code_actions::{CodeAction, CodeActionContext, CODE_ACTION_DOC_TITLE};
use lsp_types::{Range, Url};
use sway_core::{Engines, TypeId};
use sway_types::Spanned;
use tower_lsp::lsp_types::{Range, Url};

use crate::capabilities::code_actions::{CodeAction, CodeActionContext, CODE_ACTION_DOC_TITLE};

pub(crate) trait GenerateDocCodeAction<'a, T: Spanned>: CodeAction<'a, T> {
/// Returns a placeholder description as a vector of strings.
Expand Down
5 changes: 2 additions & 3 deletions sway-lsp/src/capabilities/code_actions/constant_decl/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use super::common::generate_doc::BasicDocCommentCodeAction;
use crate::capabilities::code_actions::{CodeAction, CodeActionContext};
use lsp_types::CodeActionOrCommand;
use sway_core::language::ty;
use tower_lsp::lsp_types::CodeActionOrCommand;

use super::common::generate_doc::BasicDocCommentCodeAction;

pub(crate) fn code_actions(
decl: &ty::TyConstantDecl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::capabilities::code_actions::{
common::generate_doc::GenerateDocCodeAction, CodeAction, CodeActionContext,
CODE_ACTION_DOC_TITLE,
};
use lsp_types::{Range, Url};
use sway_core::language::ty::TyEnumDecl;
use tower_lsp::lsp_types::{Range, Url};

pub(crate) struct DocCommentCodeAction<'a> {
decl: &'a TyEnumDecl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::capabilities::code_actions::{
common::generate_impl::{GenerateImplCodeAction, TAB},
CodeAction, CodeActionContext, CODE_ACTION_IMPL_TITLE,
};
use lsp_types::{Range, Url};
use sway_core::language::ty::TyEnumDecl;
use tower_lsp::lsp_types::{Range, Url};

pub(crate) struct EnumImplCodeAction<'a> {
decl: &'a TyEnumDecl,
Expand Down
2 changes: 1 addition & 1 deletion sway-lsp/src/capabilities/code_actions/enum_decl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ pub(crate) mod enum_impl;

use self::enum_impl::EnumImplCodeAction;
use crate::capabilities::code_actions::{CodeAction, CodeActionContext};
use lsp_types::CodeActionOrCommand;
use sway_core::{decl_engine::id::DeclId, language::ty};
use tower_lsp::lsp_types::CodeActionOrCommand;

use super::common::generate_doc::BasicDocCommentCodeAction;

Expand Down
2 changes: 1 addition & 1 deletion sway-lsp/src/capabilities/code_actions/enum_variant/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::capabilities::code_actions::{CodeAction, CodeActionContext};
use lsp_types::CodeActionOrCommand;
use sway_core::language::ty;
use tower_lsp::lsp_types::CodeActionOrCommand;

use super::common::generate_doc::BasicDocCommentCodeAction;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::capabilities::code_actions::{
common::generate_doc::GenerateDocCodeAction, CodeAction, CodeActionContext,
CODE_ACTION_DOC_TITLE,
};
use lsp_types::{Range, Url};
use sway_core::{language::ty::TyFunctionDecl, Engines};
use tower_lsp::lsp_types::{Range, Url};

pub(crate) struct DocCommentCodeAction<'a> {
engines: &'a Engines,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ pub(crate) mod doc_comment;

use self::doc_comment::DocCommentCodeAction;
use crate::capabilities::code_actions::{CodeAction, CodeActionContext};
use lsp_types::CodeActionOrCommand;
use sway_core::language::ty;
use tower_lsp::lsp_types::CodeActionOrCommand;

pub(crate) fn code_actions(
decl: &ty::TyFunctionDecl,
Expand Down
8 changes: 4 additions & 4 deletions sway-lsp/src/capabilities/code_actions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ use crate::core::{
token_map::TokenMap,
};
pub use crate::error::DocumentError;
use lsp_types::{
CodeAction as LspCodeAction, CodeActionDisabled, CodeActionKind, CodeActionOrCommand,
CodeActionResponse, Position, Range, TextDocumentIdentifier, TextEdit, Url, WorkspaceEdit,
};
use serde_json::Value;
use std::{collections::HashMap, sync::Arc};
use sway_core::{language::ty, Engines};
use sway_types::Spanned;
use tower_lsp::lsp_types::{
CodeAction as LspCodeAction, CodeActionDisabled, CodeActionKind, CodeActionOrCommand,
CodeActionResponse, Position, Range, TextDocumentIdentifier, TextEdit, Url, WorkspaceEdit,
};

pub(crate) const CODE_ACTION_IMPL_TITLE: &str = "Generate impl for";
pub(crate) const CODE_ACTION_NEW_TITLE: &str = "Generate `new`";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::capabilities::code_actions::{CodeAction, CodeActionContext};
use lsp_types::CodeActionOrCommand;
use sway_core::language::ty;
use tower_lsp::lsp_types::CodeActionOrCommand;

use super::common::generate_doc::BasicDocCommentCodeAction;

Expand Down
2 changes: 1 addition & 1 deletion sway-lsp/src/capabilities/code_actions/struct_decl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ pub(crate) mod struct_new;

use self::{struct_impl::StructImplCodeAction, struct_new::StructNewCodeAction};
use crate::capabilities::code_actions::{CodeAction, CodeActionContext};
use lsp_types::CodeActionOrCommand;
use sway_core::{decl_engine::id::DeclId, language::ty};
use tower_lsp::lsp_types::CodeActionOrCommand;

use super::common::generate_doc::BasicDocCommentCodeAction;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::capabilities::code_actions::{
common::generate_impl::{GenerateImplCodeAction, TAB},
CodeAction, CodeActionContext, CODE_ACTION_IMPL_TITLE,
};
use lsp_types::{Range, Url};
use sway_core::language::ty::TyStructDecl;
use tower_lsp::lsp_types::{Range, Url};

pub(crate) struct StructImplCodeAction<'a> {
decl: &'a TyStructDecl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use crate::{
},
core::{token::TypedAstToken, token_map::TokenMapExt},
};
use lsp_types::{CodeActionDisabled, Position, Range, Url};
use sway_core::language::ty::{self, TyImplTrait, TyStructDecl, TyStructField};
use sway_types::Spanned;
use tower_lsp::lsp_types::{CodeActionDisabled, Position, Range, Url};

pub(crate) struct StructNewCodeAction<'a> {
decl: &'a TyStructDecl,
Expand Down
2 changes: 1 addition & 1 deletion sway-lsp/src/capabilities/code_actions/struct_field/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::capabilities::code_actions::{CodeAction, CodeActionContext};
use lsp_types::CodeActionOrCommand;
use sway_core::language::ty;
use tower_lsp::lsp_types::CodeActionOrCommand;

use super::common::generate_doc::BasicDocCommentCodeAction;

Expand Down
8 changes: 4 additions & 4 deletions sway-lsp/src/capabilities/completion.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use lsp_types::{
CompletionItem, CompletionItemKind, CompletionItemLabelDetails, CompletionTextEdit, Position,
Range, TextEdit,
};
use sway_core::{
language::ty::{TyAstNodeContent, TyDecl, TyFunctionDecl},
namespace::Items,
Engines, TypeId, TypeInfo,
};
use sway_types::Ident;
use tower_lsp::lsp_types::{
CompletionItem, CompletionItemKind, CompletionItemLabelDetails, CompletionTextEdit, Position,
Range, TextEdit,
};

pub(crate) fn to_completion_items(
namespace: &Items,
Expand Down
3 changes: 1 addition & 2 deletions sway-lsp/src/capabilities/diagnostic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use tower_lsp::lsp_types::{Diagnostic, DiagnosticSeverity, DiagnosticTag, Position, Range};

use lsp_types::{Diagnostic, DiagnosticSeverity, DiagnosticTag, Position, Range};
use sway_error::warning::CompileWarning;
use sway_error::{error::CompileError, warning::Warning};
use sway_types::{LineCol, Spanned};
Expand Down
2 changes: 1 addition & 1 deletion sway-lsp/src/capabilities/document_symbol.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::core::token::{get_range_from_span, SymbolKind, Token};
use lsp_types::{self, Location, SymbolInformation, Url};
use sway_types::{Ident, Spanned};
use tower_lsp::lsp_types::{self, Location, SymbolInformation, Url};

pub fn to_symbol_information<I>(tokens: I, url: Url) -> Vec<SymbolInformation>
where
Expand Down
2 changes: 1 addition & 1 deletion sway-lsp/src/capabilities/formatting.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::error::LanguageServerError;
use lsp_types::{Position, Range, TextEdit};
use std::sync::Arc;
use swayfmt::Formatter;
use tower_lsp::lsp_types::{Position, Range, TextEdit};

pub fn get_page_text_edit(
text: Arc<str>,
Expand Down
2 changes: 1 addition & 1 deletion sway-lsp/src/capabilities/highlight.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::core::session::Session;
use lsp_types::{DocumentHighlight, Position, Url};
use std::sync::Arc;
use tower_lsp::lsp_types::{DocumentHighlight, Position, Url};

pub fn get_highlights(
session: Arc<Session>,
Expand Down
2 changes: 1 addition & 1 deletion sway-lsp/src/capabilities/hover/hover_link_contents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use sway_core::{
Engines, TypeId, TypeInfo,
};

use lsp_types::{Range, Url};
use sway_types::{Span, Spanned};
use tower_lsp::lsp_types::{Range, Url};

#[derive(Debug, Clone)]
pub struct RelatedType {
Expand Down
2 changes: 1 addition & 1 deletion sway-lsp/src/capabilities/hover/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use sway_core::{
Engines, TypeId,
};

use lsp_types::{self, Position, Url};
use sway_types::{Ident, Span, Spanned};
use tower_lsp::lsp_types::{self, Position, Url};

use self::hover_link_contents::HoverLinkContents;

Expand Down
2 changes: 1 addition & 1 deletion sway-lsp/src/capabilities/inlay_hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use crate::{
token::{get_range_from_span, TypedAstToken},
},
};
use lsp_types::{self, Range, Url};
use std::sync::Arc;
use sway_core::{language::ty::TyDecl, type_system::TypeInfo};
use sway_types::Spanned;
use tower_lsp::lsp_types::{self, Range, Url};

// Future PR's will add more kinds
#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down
4 changes: 2 additions & 2 deletions sway-lsp/src/capabilities/on_enter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ fn get_comment_workspace_edit(
#[cfg(test)]
mod tests {
use super::*;
use sway_lsp_test_utils::get_absolute_path;
use tower_lsp::lsp_types::{
use lsp_types::{
AnnotatedTextEdit, TextDocumentContentChangeEvent, VersionedTextDocumentIdentifier,
};
use sway_lsp_test_utils::get_absolute_path;

fn assert_text_edit(
actual: &OneOf<TextEdit, AnnotatedTextEdit>,
Expand Down
2 changes: 1 addition & 1 deletion sway-lsp/src/capabilities/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use crate::{
error::{LanguageServerError, RenameError},
utils::document::get_url_from_path,
};
use lsp_types::{Position, PrepareRenameResponse, TextEdit, Url, WorkspaceEdit};
use std::{collections::HashMap, sync::Arc};
use sway_core::{language::ty, Engines};
use sway_types::{Ident, Spanned};
use tower_lsp::lsp_types::{Position, PrepareRenameResponse, TextEdit, Url, WorkspaceEdit};

const RAW_IDENTIFIER: &str = "r#";

Expand Down
5 changes: 2 additions & 3 deletions sway-lsp/src/capabilities/runnable.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::core::token::get_range_from_span;
use lsp_types::{Command, Range};
use serde_json::{json, Value};
use sway_core::language::parsed::TreeType;
use sway_types::Span;
use tower_lsp::lsp_types::{Command, Range};

use crate::core::token::get_range_from_span;

#[derive(Debug, Eq, PartialEq, Clone)]
pub struct RunnableMainFn {
Expand Down
8 changes: 4 additions & 4 deletions sway-lsp/src/capabilities/semantic_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ use crate::core::{
session::Session,
token::{get_range_from_span, SymbolKind, Token},
};
use lsp_types::{
Range, SemanticToken, SemanticTokenModifier, SemanticTokenType, SemanticTokens,
SemanticTokensResult, Url,
};
use std::sync::{
atomic::{AtomicU32, Ordering},
Arc,
};
use sway_types::{Span, Spanned};
use tower_lsp::lsp_types::{
Range, SemanticToken, SemanticTokenModifier, SemanticTokenType, SemanticTokens,
SemanticTokensResult, Url,
};

// https://github.com/microsoft/vscode-extension-samples/blob/5ae1f7787122812dcc84e37427ca90af5ee09f14/semantic-tokens-sample/vscode.proposed.d.ts#L71
pub fn semantic_tokens_full(session: Arc<Session>, url: &Url) -> Option<SemanticTokensResult> {
Expand Down
2 changes: 1 addition & 1 deletion sway-lsp/src/core/document.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(dead_code)]
use lsp_types::{Position, Range, TextDocumentContentChangeEvent};
use ropey::Rope;
use tower_lsp::lsp_types::{Position, Range, TextDocumentContentChangeEvent};

use crate::error::DocumentError;

Expand Down
8 changes: 4 additions & 4 deletions sway-lsp/src/core/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ use crate::{
};
use dashmap::DashMap;
use forc_pkg as pkg;
use lsp_types::{
CompletionItem, GotoDefinitionResponse, Location, Position, Range, SymbolInformation,
TextDocumentContentChangeEvent, TextEdit, Url,
};
use parking_lot::RwLock;
use pkg::{manifest::ManifestFile, Programs};
use std::{
Expand All @@ -39,10 +43,6 @@ use sway_core::{
use sway_types::{Span, Spanned};
use sway_utils::helpers::get_sway_files;
use tokio::sync::Semaphore;
use tower_lsp::lsp_types::{
CompletionItem, GotoDefinitionResponse, Location, Position, Range, SymbolInformation,
TextDocumentContentChangeEvent, TextEdit, Url,
};

pub type Documents = DashMap<String, TextDocument>;
pub type ProjectDirectory = PathBuf;
Expand Down
Loading

0 comments on commit c9175cb

Please sign in to comment.