Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 38 additions & 101 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ anyhow = "1.0.72"
clap = { version = "4.3.17", features = ["derive", "env"] }
log = { version = "0.4.19", features = ["kv_unstable", "kv_unstable_serde"] }
lsp-server = "0.7.2"
lsp-types = "0.94.0"
lsp-types = { package = "gen-lsp-types", version = "0.5.0" }
serde = { version = "1.0.173", features = ["derive"] }
serde_json = "1.0.103"
structured-logger = "1.0.1"
Expand Down
6 changes: 3 additions & 3 deletions lsp/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ fn handle_completion(req: Request) -> Option<HtmxResult> {

match completion.context {
Some(CompletionContext {
trigger_kind: CompletionTriggerKind::TRIGGER_CHARACTER,
trigger_kind: CompletionTriggerKind::TriggerCharacter,
..
})
| Some(CompletionContext {
trigger_kind: CompletionTriggerKind::INVOKED,
trigger_kind: CompletionTriggerKind::Invoked,
..
}) => {
let items = match hx_completion(completion.text_document_position) {
let items = match hx_completion(completion.text_document_position_params) {
Some(items) => items,
None => {
error!("EMPTY RESULTS OF COMPLETION");
Expand Down
23 changes: 14 additions & 9 deletions lsp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use anyhow::Result;
use htmx::HxCompletionValue;
use log::{debug, error, info, warn};
use lsp_types::{
Command, CompletionItem, CompletionItemKind, CompletionList, HoverContents, InitializeParams,
InsertTextFormat, MarkupContent, ServerCapabilities, TextDocumentSyncCapability,
TextDocumentSyncKind, WorkDoneProgressOptions,
Command, CompletionItem, CompletionItemKind, CompletionList, Contents, InitializeParams,
InsertTextFormat, MarkupContent, ServerCapabilities, TextDocumentSyncKind,
WorkDoneProgressOptions,
};

use lsp_server::{Connection, Message, Response};
Expand All @@ -29,19 +29,22 @@ fn to_completion_list(items: HxCompletionValue) -> CompletionList {
.iter()
.map(|x| CompletionItem {
label: x.name.to_string(),
kind: Some(CompletionItemKind::VALUE),
kind: Some(CompletionItemKind::Value),
detail: Some(x.desc.to_string()),
// TODO: Figure out if we can use edit_text instead of insert_text here
insert_text: Some(x.name.to_string() + "=\"$1\""),
insert_text_format: Some(InsertTextFormat::SNIPPET),
insert_text_format: Some(InsertTextFormat::Snippet),
command: Some(Command {
title: String::from("Suggest"),
command: "editor.action.triggerSuggest".to_string(),
arguments: None,
tooltip: None,
}),
..Default::default()
})
.collect(),
apply_kind: None,
item_defaults: None,
},
HxCompletionValue::AttributeValue(items) => CompletionList {
is_incomplete: true,
Expand All @@ -50,11 +53,13 @@ fn to_completion_list(items: HxCompletionValue) -> CompletionList {
.iter()
.map(|x| CompletionItem {
label: x.name.to_string(),
kind: Some(CompletionItemKind::PROPERTY),
kind: Some(CompletionItemKind::Property),
detail: Some(x.desc.to_string()),
..Default::default()
})
.collect(),
apply_kind: None,
item_defaults: None,
},
}
}
Expand Down Expand Up @@ -94,7 +99,7 @@ fn main_loop(connection: Connection, params: serde_json::Value) -> Result<()> {
Some(HtmxResult::AttributeHover(hover_resp)) => {
debug!("main_loop - hover response: {:?}", hover_resp);
let hover_response = lsp_types::Hover {
contents: HoverContents::Markup(MarkupContent {
contents: Contents::MarkupContent(MarkupContent {
kind: lsp_types::MarkupKind::Markdown,
value: hover_resp.value.to_string(),
}),
Expand Down Expand Up @@ -153,7 +158,7 @@ pub fn start_lsp() -> Result<()> {

// Run the server and wait for the two threads to end (typically by trigger LSP Exit event).
let server_capabilities = serde_json::to_value(ServerCapabilities {
text_document_sync: Some(TextDocumentSyncCapability::Kind(TextDocumentSyncKind::FULL)),
text_document_sync: Some(TextDocumentSyncKind::Full.into()),
completion_provider: Some(lsp_types::CompletionOptions {
resolve_provider: Some(false),
trigger_characters: Some(vec!["-".to_string(), "\"".to_string(), " ".to_string()]),
Expand All @@ -164,7 +169,7 @@ pub fn start_lsp() -> Result<()> {
completion_item: None,
}),

hover_provider: Some(lsp_types::HoverProviderCapability::Simple(true)),
hover_provider: Some(true.into()),

..Default::default()
})
Expand Down
4 changes: 2 additions & 2 deletions lsp/src/text_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
sync::{Arc, Mutex, OnceLock},
};

use lsp_types::{TextDocumentPositionParams, Url};
use lsp_types::{TextDocumentPositionParams, Uri};

type TxtStore = HashMap<String, String>;

Expand All @@ -29,7 +29,7 @@ pub fn init_text_store() {
_ = TEXT_STORE.set(Arc::new(Mutex::new(TextStore(HashMap::new()))));
}

pub fn get_text_document(uri: &Url) -> Option<String> {
pub fn get_text_document(uri: &Uri) -> Option<String> {
return TEXT_STORE
.get()
.expect("text store not initialized")
Expand Down
2 changes: 1 addition & 1 deletion util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ license = "MIT"
[dependencies]
log.workspace = true
structured-logger.workspace = true
lsp-types = "0.94.0"
lsp-types.workspace = true