-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handle document open and change in lsp
- Loading branch information
1 parent
bd46a3d
commit 2caae8b
Showing
7 changed files
with
88 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use std::collections::HashMap; | ||
|
||
use lsp_types::Uri; | ||
|
||
pub struct DocumentStore { | ||
store: HashMap<Uri, String>, | ||
} | ||
|
||
use anyhow::{anyhow, Result}; | ||
|
||
impl DocumentStore { | ||
pub fn new() -> DocumentStore { | ||
DocumentStore { | ||
store: HashMap::new(), | ||
} | ||
} | ||
|
||
pub fn put_document(&mut self, uri: Uri, document: String) { | ||
self.store.insert(uri, document); | ||
} | ||
|
||
pub fn get_document(&self, uri: &Uri) -> Result<&String> { | ||
self.store | ||
.get(uri) | ||
.ok_or_else(|| anyhow!("Document not found for URI: {:?}", uri)) | ||
} | ||
} | ||
|
||
impl Default for DocumentStore { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod document_store; | ||
pub mod logging; | ||
pub mod lsp; | ||
pub mod rpc; |
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,17 @@ | ||
use anyhow::anyhow; | ||
use anyhow::Result; | ||
use lsp_types::DidChangeTextDocumentParams; | ||
|
||
use super::SonOfAnton; | ||
|
||
pub fn handle_change(params: DidChangeTextDocumentParams, lsp: &mut SonOfAnton) -> Result<()> { | ||
let document_change = params | ||
.content_changes | ||
.first() | ||
.ok_or_else(|| anyhow!("Change event contained no changes"))?; | ||
|
||
lsp.document_store | ||
.put_document(params.text_document.uri, document_change.text.clone()); | ||
|
||
Ok(()) | ||
} |
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,12 @@ | ||
use lsp_types::DidOpenTextDocumentParams; | ||
use tracing::{event, Level}; | ||
|
||
use super::SonOfAnton; | ||
|
||
pub fn handle_open(params: DidOpenTextDocumentParams, lsp: &mut SonOfAnton) { | ||
let uri = params.text_document.uri; | ||
event!(Level::DEBUG, "Got open: {:?}", uri); | ||
|
||
lsp.document_store | ||
.put_document(uri, params.text_document.text); | ||
} |
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