-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tele JB sync #41
Merged
Merged
tele JB sync #41
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do u move Document here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bc Document is not being used anywhere else but in receive_workspace_changes