Skip to content

Commit

Permalink
refactor(#331): simplify ident dict code
Browse files Browse the repository at this point in the history
  • Loading branch information
grantlemons committed Dec 31, 2024
1 parent f8e6e77 commit 50a7c14
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions harper-ls/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use harper_core::{
};
use harper_html::HtmlParser;
use harper_literate_haskell::LiterateHaskellParser;
use itertools::Itertools;
use serde_json::Value;
use tokio::sync::{Mutex, RwLock};
use tower_lsp::jsonrpc::Result;
Expand Down Expand Up @@ -183,14 +184,14 @@ impl Backend {

let parser: Option<Box<dyn Parser>> =
if let Some(ts_parser) = CommentParser::new_from_language_id(language_id) {
let source: Vec<char> = text.chars().collect();
let source = Arc::new(source);
let source = text.chars().collect_vec();

if let Some(new_dict) = ts_parser.create_ident_dict(source.as_slice()) {
if let Some(new_dict) = ts_parser.create_ident_dict(&source) {
let new_dict = Arc::new(new_dict);

if doc_state.ident_dict != new_dict {
doc_state.ident_dict = new_dict.clone();

let mut merged = self.generate_file_dictionary(url).await?;
merged.add_dictionary(new_dict);
let merged = Arc::new(merged);
Expand All @@ -206,15 +207,15 @@ impl Backend {
Some(Box::new(ts_parser))
}
} else if language_id == "lhaskell" {
let source: Vec<char> = text.chars().collect();
let source = Arc::new(source);

let source = text.chars().collect_vec();
let parser = LiterateHaskellParser;
if let Some(new_dict) = parser.create_ident_dict(source.as_slice()) {

if let Some(new_dict) = parser.create_ident_dict(&source) {
let new_dict = Arc::new(new_dict);

if doc_state.ident_dict != new_dict {
doc_state.ident_dict = new_dict.clone();

let mut merged = self.generate_file_dictionary(url).await?;
merged.add_dictionary(new_dict);
let merged = Arc::new(merged);
Expand Down

0 comments on commit 50a7c14

Please sign in to comment.