Skip to content

Commit

Permalink
Publish diagnostics more often + improve spell check message
Browse files Browse the repository at this point in the history
  • Loading branch information
elijah-potter committed Jan 19, 2024
1 parent 703da16 commit bdba195
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
6 changes: 3 additions & 3 deletions harper-core/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ impl Document {
span.get_content(&self.source)
}

pub fn get_content_string(&self, span: Span) -> String {
pub fn get_span_content_str(&self, span: Span) -> String {
String::from_iter(self.get_span_content(span))
}

pub fn get_full_string(&self) -> String {
self.get_content_string(Span {
self.get_span_content_str(Span {
start: 0,
end: self.source.len(),
})
Expand Down Expand Up @@ -160,7 +160,7 @@ impl Document {
impl Display for Document {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
for token in &self.tokens {
write!(f, "{}", self.get_content_string(token.span))?;
write!(f, "{}", self.get_span_content_str(token.span))?;
}

Ok(())
Expand Down
5 changes: 4 additions & 1 deletion harper-core/src/linting/spell_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ pub fn spell_check(document: &Document, _dictionary: &Dictionary) -> Vec<Lint> {
span: word.span,
lint_kind: LintKind::Spelling,
suggestions: suggestions.collect(),
message: "Did you mean to spell it this way?".to_string(),
message: format!(
"Did you mean to spell “{}” this way?",
document.get_span_content_str(word.span)
),
})
}

Expand Down
10 changes: 7 additions & 3 deletions harper-ls/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,23 @@ impl LanguageServer for Backend {
self.publish_diagnostics(&params.text_document.uri).await;
}

async fn did_open(&self, _: DidOpenTextDocumentParams) {
async fn did_open(&self, params: DidOpenTextDocumentParams) {
self.client
.log_message(MessageType::INFO, "File opened!")
.await;

self.publish_diagnostics(&params.text_document.uri).await;
}

async fn did_change(&self, _: DidChangeTextDocumentParams) {
async fn did_change(&self, params: DidChangeTextDocumentParams) {
self.client
.log_message(MessageType::INFO, "File changed!")
.await;

self.publish_diagnostics(&params.text_document.uri).await;
}

async fn did_close(&self, _: DidCloseTextDocumentParams) {
async fn did_close(&self, params: DidCloseTextDocumentParams) {
self.client
.log_message(MessageType::INFO, "File closed!")
.await;
Expand Down

0 comments on commit bdba195

Please sign in to comment.