From 236ded01309074e112e5aed0869c575de1e2adef Mon Sep 17 00:00:00 2001 From: Kinflou Date: Wed, 2 Sep 2026 17:27:44 +0800 Subject: [PATCH] chore: revive against current comline-core MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The LSP hadn't been built since the core grammar / IR drifted; it now compiles and all tests pass (39 + 2 e2e + 4 integration). - AST declarations are `Spanned` now — deref before matching (`match &**decl`) in symbols / hover / references. - `Declaration` gained `Error` / `Settings` / `Validator` — handled (not surfaced in the outline yet). - grammar `Type::I8..I64` -> `S8..S64` (signed prefix); `format_type` gains the `Union` and `Unit` arms the grammar added. - `comline-core` by git rev (core 50c17cc), like every other repo, so it builds standalone; a commented `[patch]` for sibling-checkout dev. - a CI workflow (cargo build + test), matching the other repos. - trimmed dead imports; `license = "GPL-3.0-only"`. --- .github/workflows/ci.yml | 18 ++++++++++++++++++ Cargo.toml | 13 +++++++++++-- src/analysis/symbols.rs | 14 +++++++++----- src/handlers/code_actions.rs | 2 +- src/handlers/definition.rs | 2 +- src/handlers/hover.rs | 27 +++++++++++++++++---------- src/handlers/references.rs | 2 +- src/handlers/semantic_tokens.rs | 2 +- src/handlers/signature_help.rs | 2 +- src/handlers/symbols.rs | 4 ++-- 10 files changed, 62 insertions(+), 24 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..0621f86 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,18 @@ +name: CI + +on: + push: + pull_request: + +env: + CARGO_TERM_COLOR: always + +jobs: + build_and_test: + name: Rust project - stable + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: rustup update stable && rustup default stable + - run: cargo build --verbose + - run: cargo test --verbose diff --git a/Cargo.toml b/Cargo.toml index d836fd4..cbf8636 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ name = "comline-language-server" version = "0.1.0" edition = "2021" +license = "GPL-3.0-only" [[bin]] name = "comline-lsp" @@ -14,8 +15,10 @@ tokio = { version = "1.35", features = ["full"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -# Comline Core Integration -comline-core = { path = "../core/core" } +# Comline Core Integration — by git rev, like the rest of the tree (the LSP +# links `comline-core` and is part of the GPL toolchain). Local iteration: +# uncomment the `[patch]` below onto a sibling `core` checkout. +comline-core = { git = "https://github.com/ComlineProject/core", rev = "50c17cc740676416e945582dd6e2547e8535ac03" } rust-sitter = "0.4.5" # For parse error types # Diagnostics & Error Reporting @@ -27,3 +30,9 @@ tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } anyhow = "1.0" dashmap = "5.5" + +# Local iteration against a sibling `core` checkout — uncomment to build +# `comline-core` from the working tree instead of the pinned git rev. +# Re-comment before pushing; CI has no sibling checkout. +# [patch."https://github.com/ComlineProject/core"] +# comline-core = { path = "../core/core" } diff --git a/src/analysis/symbols.rs b/src/analysis/symbols.rs index 5f53468..107634b 100644 --- a/src/analysis/symbols.rs +++ b/src/analysis/symbols.rs @@ -65,11 +65,11 @@ pub fn build_symbol_table(document: &Document, uri: &Url, source: &str) -> Symbo let mut table = SymbolTable::new(); // Track line starts for position calculation - let line_starts = build_line_starts(source); + let _line_starts = build_line_starts(source); - // Walk through all declarations + // Walk through all declarations (each is `Spanned` — deref to match) for declaration in &document.0 { - match declaration { + match &**declaration { Declaration::Struct(s) => { let name = s.name(); let children: Vec = s.fields().iter().map(|f| f.name()).collect(); @@ -146,8 +146,12 @@ pub fn build_symbol_table(document: &Document, uri: &Url, source: &str) -> Symbo }, ); } - Declaration::Import(_) | Declaration::Use(_) => { - // Imports don't go in the symbol table (for now) + Declaration::Import(_) + | Declaration::Use(_) + | Declaration::Error(_) + | Declaration::Settings(_) + | Declaration::Validator(_) => { + // Not surfaced in the outline (for now) } } } diff --git a/src/handlers/code_actions.rs b/src/handlers/code_actions.rs index d1e6fa7..8d76728 100644 --- a/src/handlers/code_actions.rs +++ b/src/handlers/code_actions.rs @@ -1,6 +1,6 @@ // Code actions handler - provides quick fixes and refactorings -use tower_lsp::lsp_types::{CodeAction, CodeActionOrCommand, CodeActionParams, Url}; +use tower_lsp::lsp_types::{CodeActionOrCommand, CodeActionParams, Url}; /// Get code actions for a given range pub fn get_code_actions( diff --git a/src/handlers/definition.rs b/src/handlers/definition.rs index e368370..4d7cb08 100644 --- a/src/handlers/definition.rs +++ b/src/handlers/definition.rs @@ -3,7 +3,7 @@ use crate::analysis::symbols; use crate::parser; use crate::util::position_to_offset; -use tower_lsp::lsp_types::{GotoDefinitionResponse, Location, Position, Url}; +use tower_lsp::lsp_types::{GotoDefinitionResponse, Position, Url}; /// Find the definition of a symbol at a position pub fn find_definition(source: &str, uri: &Url, position: Position) -> Option { diff --git a/src/handlers/hover.rs b/src/handlers/hover.rs index 3ebe6fb..c126037 100644 --- a/src/handlers/hover.rs +++ b/src/handlers/hover.rs @@ -4,7 +4,7 @@ use crate::analysis::symbols; use crate::parser; use crate::util::position_to_offset; use comline_core::schema::idl::grammar::{Declaration, Type}; -use tower_lsp::lsp_types::{Hover, HoverContents, HoverParams, MarkedString, Position, Url}; +use tower_lsp::lsp_types::{Hover, HoverContents, MarkedString, Position, Url}; /// Get hover information at a position pub fn get_hover_info(source: &str, uri: &Url, position: Position) -> Option { @@ -164,10 +164,10 @@ fn create_field_hover(info: &str) -> Hover { /// Format a type for display fn format_type(ty: &Type) -> String { match ty { - Type::I8(_) => "i8".to_string(), - Type::I16(_) => "i16".to_string(), - Type::I32(_) => "i32".to_string(), - Type::I64(_) => "i64".to_string(), + Type::S8(_) => "s8".to_string(), + Type::S16(_) => "s16".to_string(), + Type::S32(_) => "s32".to_string(), + Type::S64(_) => "s64".to_string(), Type::U8(_) => "u8".to_string(), Type::U16(_) => "u16".to_string(), Type::U32(_) => "u32".to_string(), @@ -185,6 +185,13 @@ fn format_type(ty: &Type) -> String { format!("{}[]", format_type(arr.elem_type())) } } + Type::Union(u) => u + .members() + .iter() + .map(format_type) + .collect::>() + .join(" | "), + Type::Unit(_) => "()".to_string(), } } @@ -220,7 +227,7 @@ fn find_type_at_position(document: &comline_core::schema::idl::grammar::Document _ => { // Check if it's a user-defined type for decl in &document.0 { - match decl { + match &**decl { Declaration::Struct(s) if s.name() == word => return Some("struct"), Declaration::Enum(e) if e.name() == word => return Some("enum"), Declaration::Protocol(p) if p.name() == word => return Some("protocol"), @@ -241,7 +248,7 @@ fn find_field_info(_document: &comline_core::schema::idl::grammar::Document, _wo // Helper functions to find declarations fn find_struct_declaration<'a>(document: &'a comline_core::schema::idl::grammar::Document, name: &str) -> Option<&'a comline_core::schema::idl::grammar::Struct> { for decl in &document.0 { - if let Declaration::Struct(s) = decl { + if let Declaration::Struct(s) = &**decl { if s.name() == name { return Some(s); } @@ -252,7 +259,7 @@ fn find_struct_declaration<'a>(document: &'a comline_core::schema::idl::grammar: fn find_enum_declaration<'a>(document: &'a comline_core::schema::idl::grammar::Document, name: &str) -> Option<&'a comline_core::schema::idl::grammar::Enum> { for decl in &document.0 { - if let Declaration::Enum(e) = decl { + if let Declaration::Enum(e) = &**decl { if e.name() == name { return Some(e); } @@ -263,7 +270,7 @@ fn find_enum_declaration<'a>(document: &'a comline_core::schema::idl::grammar::D fn find_protocol_declaration<'a>(document: &'a comline_core::schema::idl::grammar::Document, name: &str) -> Option<&'a comline_core::schema::idl::grammar::Protocol> { for decl in &document.0 { - if let Declaration::Protocol(p) = decl { + if let Declaration::Protocol(p) = &**decl { if p.name() == name { return Some(p); } @@ -274,7 +281,7 @@ fn find_protocol_declaration<'a>(document: &'a comline_core::schema::idl::gramma fn find_const_declaration<'a>(document: &'a comline_core::schema::idl::grammar::Document, name: &str) -> Option<&'a comline_core::schema::idl::grammar::Const> { for decl in &document.0 { - if let Declaration::Const(c) = decl { + if let Declaration::Const(c) = &**decl { if c.name() == name { return Some(c); } diff --git a/src/handlers/references.rs b/src/handlers/references.rs index 54f56a1..0a6eb12 100644 --- a/src/handlers/references.rs +++ b/src/handlers/references.rs @@ -57,7 +57,7 @@ pub fn find_references( // Search for type references in all declarations for decl in &document.0 { - match decl { + match &**decl { Declaration::Struct(s) => { // Check each field type for field in s.fields() { diff --git a/src/handlers/semantic_tokens.rs b/src/handlers/semantic_tokens.rs index 5023102..92494eb 100644 --- a/src/handlers/semantic_tokens.rs +++ b/src/handlers/semantic_tokens.rs @@ -1,7 +1,7 @@ // Semantic tokens handler - provides enhanced syntax highlighting use tower_lsp::lsp_types::{ - SemanticToken, SemanticTokenType, SemanticTokens, SemanticTokensResult, Url, + SemanticTokens, SemanticTokensResult, Url, }; /// Generate semantic tokens for a document (basic stub implementation) diff --git a/src/handlers/signature_help.rs b/src/handlers/signature_help.rs index a0d82e9..9195e68 100644 --- a/src/handlers/signature_help.rs +++ b/src/handlers/signature_help.rs @@ -1,7 +1,7 @@ // Signature help handler - provides function signature information use tower_lsp::lsp_types::{ - ParameterInformation, ParameterLabel, Position, SignatureHelp, SignatureInformation, Url, + Position, SignatureHelp, Url, }; /// Get signature help for function calls diff --git a/src/handlers/symbols.rs b/src/handlers/symbols.rs index d2a35ed..c85c073 100644 --- a/src/handlers/symbols.rs +++ b/src/handlers/symbols.rs @@ -1,6 +1,6 @@ // Symbol provider for LSP document symbols -use crate::analysis::symbols::{self, SymbolTable}; +use crate::analysis::symbols; use crate::parser; use tower_lsp::lsp_types::{DocumentSymbol, Range, SymbolInformation, SymbolKind, Url}; @@ -125,7 +125,7 @@ fn byte_offset_to_range(source: &str, offset: usize, length: usize) -> Range { } /// Get workspace symbols (basic implementation - searches all symbols by name) -pub fn get_workspace_symbols(query: &str) -> Vec { +pub fn get_workspace_symbols(_query: &str) -> Vec { // TODO: Implement workspace-wide symbol search // This would require maintaining a workspace-level symbol index vec![]