-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LSP functions available via HTTP as well removed unuseful prints added debug logs; minor * added debug logs; minor * implemented suggestions from @Kirill * fixes for rh and comp_counters * changes requested from @oleg
- Loading branch information
Showing
13 changed files
with
225 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use axum::Extension; | ||
use axum::response::Result; | ||
use hyper::{Body, Response, StatusCode}; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_json::json; | ||
use url::Url; | ||
use crate::custom_error::ScratchError; | ||
use crate::global_context::SharedGlobalContext; | ||
use crate::receive_workspace_changes; | ||
|
||
|
||
#[derive(Serialize, Deserialize, Clone)] | ||
struct PostInit { | ||
pub project_roots: Vec<Url>, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Clone)] | ||
struct PostDocument { | ||
pub uri: Url, | ||
pub text: String, | ||
} | ||
|
||
|
||
pub async fn handle_v1_lsp_initialize( | ||
Extension(global_context): Extension<SharedGlobalContext>, | ||
body_bytes: hyper::body::Bytes, | ||
) -> Result<Response<Body>, ScratchError> { | ||
let post = serde_json::from_slice::<PostInit>(&body_bytes).map_err(|e| { | ||
ScratchError::new(StatusCode::BAD_REQUEST, format!("JSON problem: {}", e)) | ||
})?; | ||
|
||
Ok(Response::builder() | ||
.status(StatusCode::OK) | ||
.body(Body::from(json!({"success": 1}).to_string())) | ||
.unwrap()) | ||
} | ||
|
||
pub async fn handle_v1_lsp_did_change( | ||
Extension(global_context): Extension<SharedGlobalContext>, | ||
body_bytes: hyper::body::Bytes, | ||
) -> Result<Response<Body>, ScratchError> { | ||
let post = serde_json::from_slice::<PostDocument>(&body_bytes).map_err(|e| { | ||
ScratchError::new(StatusCode::BAD_REQUEST, format!("JSON problem: {}", e)) | ||
})?; | ||
|
||
receive_workspace_changes::on_did_change( | ||
global_context.clone(), | ||
&post.uri.to_string(), | ||
&post.text, | ||
).await; | ||
|
||
Ok(Response::builder() | ||
.status(StatusCode::OK) | ||
.body(Body::from(json!({"success": 1}).to_string())) | ||
.unwrap()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use std::collections::HashMap; | ||
use std::fmt::Display; | ||
use std::sync::Arc; | ||
use std::time::Instant; | ||
use ropey::Rope; | ||
|
||
use tokio::sync::RwLock as ARwLock; | ||
use tracing::{info}; | ||
|
||
use crate::global_context; | ||
use crate::telemetry; | ||
|
||
|
||
|
||
#[derive(Debug)] | ||
pub struct Document { | ||
#[allow(dead_code)] | ||
pub language_id: String, | ||
pub text: Rope, | ||
} | ||
|
||
impl Document { | ||
pub fn new(language_id: String, text: Rope) -> Self { | ||
Self { language_id, text } | ||
} | ||
} | ||
|
||
|
||
pub async fn on_did_open( | ||
gcx: Arc<ARwLock<global_context::GlobalContext>>, | ||
uri: &String, | ||
text: &String, | ||
language_id: &String, | ||
) { | ||
let t0 = Instant::now(); | ||
let gcx_locked = gcx.read().await; | ||
let document_map = &gcx_locked.lsp_backend_document_state.document_map; | ||
let rope = ropey::Rope::from_str(&text); | ||
let mut document_map_locked = document_map.write().await; | ||
*document_map_locked | ||
.entry(uri.clone()) | ||
.or_insert(Document::new("unknown".to_owned(), Rope::new())) = | ||
Document::new(language_id.clone(), rope); | ||
info!("{} opened, save time: {:?}", uri, t0.elapsed()); | ||
} | ||
|
||
pub async fn on_did_change( | ||
gcx: Arc<ARwLock<global_context::GlobalContext>>, | ||
uri: &String, | ||
text: &String, | ||
) { | ||
let t0 = Instant::now(); | ||
|
||
let gcx_locked = gcx.read().await; | ||
let document_map = &gcx_locked.lsp_backend_document_state.document_map; | ||
let rope = ropey::Rope::from_str(&text); | ||
let mut document_map_locked = document_map.write().await; | ||
let doc = document_map_locked | ||
.entry(uri.clone()) | ||
.or_insert(Document::new("unknown".to_owned(), Rope::new())); | ||
doc.text = rope; | ||
|
||
info!("{} changed, save time: {:?}", uri, t0.elapsed()); | ||
let t1 = Instant::now(); | ||
telemetry::snippets_collection::sources_changed( | ||
gcx.clone(), | ||
uri, | ||
text, | ||
).await; | ||
info!("{} changed, telemetry time: {:?}", uri, t1.elapsed()); | ||
} |
Oops, something went wrong.