Skip to content

Commit

Permalink
directory scan
Browse files Browse the repository at this point in the history
  • Loading branch information
gimalay committed Feb 22, 2025
1 parent 117784d commit 754a660
Show file tree
Hide file tree
Showing 23 changed files with 156 additions and 118 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ IWE includes a debug mode, which can be enabled by setting the `IWE_DEBUG` envir
export IWE_DEBUG=true; nvim
```

## Plugins / Packges
## Plugins / Packages

This repository is for Rust code and crates publishing only. Plugins and packages are in separate repositories. If you are willing to help and with non-listed package type, I will add a repo for it.

Expand Down
2 changes: 1 addition & 1 deletion crates/iwe/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fn main() {
debug!("parsing arguments");
let app = App::parse();

debug!("starting command procesing");
debug!("starting command processing");
match app.command {
Command::Normalize(normalize) => {
normalize_command(normalize);
Expand Down
23 changes: 7 additions & 16 deletions crates/iwes/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use std::path::PathBuf;
use std::str::FromStr;
use std::{collections::HashMap, path::PathBuf};

use anyhow::Result;
use liwe::model::{graph::MarkdownOptions, Key};
use liwe::model::graph::MarkdownOptions;
use lsp_server::Connection;

use liwe::fs::new_for_path;
use liwe::fs::{new_for_path, new_from_hashmap};
use router::{LspClient, Router, ServerConfig};

mod router;

#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, PartialEq, Eq)]
pub struct InitializeParams {
pub state: Option<String>,
pub state: Option<HashMap<String, String>>,
pub sequential_ids: Option<bool>,
pub client_name: Option<String>,
}
Expand All @@ -32,21 +32,12 @@ pub fn main_loop(
.map(|_| LspClient::Helix)
.unwrap_or(LspClient::Unknown);

let router = if let Some(state) = &(&initialize_params).state {
let router = if let Some(state) = initialize_params.state {
Router::new(
connection.sender,
ServerConfig {
base_path: base_path.clone(),
state: state
.split("\n_\n")
.enumerate()
.map(|(index, text)| {
(
Key::from_file_name(&(index + 1).to_string()),
text.trim().to_string(),
)
})
.collect(),
state: new_from_hashmap(state),
sequential_ids: Some(true),
lsp_client: client,
markdown_options,
Expand Down
8 changes: 4 additions & 4 deletions crates/iwes/src/router.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::collections::HashMap;
use std::panic;

use anyhow::{bail, Result};
use crossbeam_channel::{select, Receiver, Sender};
use liwe::model::graph::MarkdownOptions;
use liwe::model::State;
use log::{debug, error};
use lsp_server::{ErrorCode, Message, Request};
use lsp_server::{Notification, Response};
Expand All @@ -15,8 +17,6 @@ use lsp_types::{CompletionParams, GotoDefinitionParams};
use serde::Deserialize;
use serde_json::to_value;

use liwe::model::State;

use self::server::Server;

pub mod server;
Expand Down Expand Up @@ -144,14 +144,14 @@ impl Router {
.map(|params| self.server.handle_inline_values(params))
.map(|response| to_value(response).unwrap()),
"textDocument/documentSymbol" => DocumentSymbolParams::deserialize(request.params)
.map(|params| self.server.handle_ducment_symbols(params))
.map(|params| self.server.handle_document_symbols(params))
.map(|response| to_value(response).unwrap()),
"textDocument/definition" => GotoDefinitionParams::deserialize(request.params)
.map(|params| self.server.handle_goto_definition(params))
.map(|response| to_value(response).unwrap()),
"workspace/symbol" => WorkspaceSymbolParams::deserialize(request.params)
.map(|params| self.server.handle_workspace_symbols(params)) // Completion::METHOD => {
.map(|respons| to_value(respons).unwrap()),
.map(|response| to_value(response).unwrap()),
"textDocument/completion" => CompletionParams::deserialize(request.params)
.map(|params| self.server.handle_completion(params))
.map(|response| to_value(response).unwrap()),
Expand Down
8 changes: 3 additions & 5 deletions crates/iwes/src/router/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl Server {
.graph()
.get_block_references_to(key)
.iter()
.map(|id| self.database.graph().get_container_doucment_ref_text(*id))
.map(|id| self.database.graph().get_container_document_ref_text(*id))
.sorted()
.dedup()
.map(|text| hint_at(&format!("↖{}", text), 0))
Expand All @@ -220,7 +220,7 @@ impl Server {
vec![]
}

pub fn handle_ducment_symbols(&self, params: DocumentSymbolParams) -> Vec<SymbolInformation> {
pub fn handle_document_symbols(&self, params: DocumentSymbolParams) -> Vec<SymbolInformation> {
let key = params.text_document.uri.to_key(&self.base_path);
let id = self
.database
Expand Down Expand Up @@ -261,7 +261,7 @@ impl Server {
link.key_range()
.map(|range| PrepareRenameResponse::RangeWithPlaceholder {
range: to_range(range),
placeholder: link.ref_key().unwrap().to_rel_link_url(),
placeholder: link.ref_key().unwrap().last_url_segment(),
})
})
}
Expand Down Expand Up @@ -419,8 +419,6 @@ impl Server {
let context = self.database.graph();
let base_path: &BasePath = &self.base_path;

dbg!(self.lsp_client);

context
.get_node_id_at(
&params.text_document.uri.to_key(base_path),
Expand Down
29 changes: 18 additions & 11 deletions crates/iwes/tests/fixture.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use std::{
cell::{Cell, RefCell},
collections::HashMap,
time::Duration,
};

use assert_json_diff::assert_json_eq;
use crossbeam_channel::{after, select, Receiver};
use liwe::model::graph::MarkdownOptions;
use liwe::{model::graph::MarkdownOptions, state::from_indoc};
use lsp_server::{Connection, Message, Notification, Request, ResponseError};
use lsp_types::{
notification::{DidChangeTextDocument, DidSaveTextDocument, Exit},
Expand Down Expand Up @@ -70,38 +71,45 @@ impl Fixture {
pub fn new() -> Fixture {
Self::with("\n")
}

pub fn with_kv(kv: Vec<(&str, &str)>) -> Fixture {
let state: HashMap<String, String> = kv
.into_iter()
.map(|(k, v)| (k.to_string(), v.to_string()))
.collect();
Self::with_options_and_client(state, MarkdownOptions::default(), "")
}

pub fn with(indoc: &str) -> Fixture {
Self::with_options(indoc, MarkdownOptions::default())
Self::with_options_and_client(from_indoc(indoc), MarkdownOptions::default(), "")
}

pub fn with_options(indoc: &str, markdown_options: MarkdownOptions) -> Fixture {
Self::with_options_and_client(indoc, markdown_options, "")
Self::with_options_and_client(from_indoc(indoc), markdown_options, "")
}

pub fn with_client(indoc: &str, client: &str) -> Fixture {
Self::with_options_and_client(indoc, MarkdownOptions::default(), client)
Self::with_options_and_client(from_indoc(indoc), MarkdownOptions::default(), client)
}

pub fn with_options_and_client(
indoc: &str,
state: HashMap<String, String>,
markdown_options: MarkdownOptions,
lsp_client_name: &str,
) -> Fixture {
let (connection, client) = Connection::memory();
let client_name = Some(lsp_client_name.to_string());

let content = indoc.to_string();

let _thread: std::thread::JoinHandle<()> = std::thread::Builder::new()
.name("test server".to_owned())
.spawn(move || {
main_loop(
connection,
serde_json::to_value(InitializeParams {
state: if content.is_empty() {
state: if state.is_empty() {
None
} else {
Some(content.clone())
Some(state.clone())
},
client_name,
sequential_ids: Some(true),
Expand Down Expand Up @@ -167,11 +175,10 @@ impl Fixture {
R::Params: Serialize,
{
let actual: Value = self.send_request::<R>(params);
dbg!(actual.clone());
assert_json_eq!(&expected, &actual);
}

pub fn format_doucment(&self, params: DocumentFormattingParams, expected: Vec<TextEdit>) {
pub fn format_document(&self, params: DocumentFormattingParams, expected: Vec<TextEdit>) {
self.assert_response::<Formatting>(params, Some(expected));
}

Expand Down
10 changes: 5 additions & 5 deletions crates/iwes/tests/format_document_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fn update_link_titles() {
}

#[test]
fn updte_ref_titles_after_change() {
fn update_ref_titles_after_change() {
assert_formatted_after_change(
indoc! {"
# test
Expand All @@ -142,7 +142,7 @@ fn updte_ref_titles_after_change() {
}

#[test]
fn updte_ref_titles_after_new_file_change() {
fn update_ref_titles_after_new_file_change() {
assert_formatted_after_change(
indoc! {"
# test
Expand All @@ -160,7 +160,7 @@ fn updte_ref_titles_after_new_file_change() {
fn assert_formatted(source: &str, formatted: &str) {
let fixture = Fixture::with(source);

fixture.format_doucment(
fixture.format_document(
DocumentFormattingParams {
text_document: TextDocumentIdentifier { uri: uri(1) },
options: Default::default(),
Expand All @@ -181,7 +181,7 @@ fn assert_formatted_with_extension(source: &str, formatted: &str) {
},
);

fixture.format_doucment(
fixture.format_document(
DocumentFormattingParams {
text_document: TextDocumentIdentifier { uri: uri(1) },
options: Default::default(),
Expand Down Expand Up @@ -209,7 +209,7 @@ fn assert_formatted_after_change(source: &str, change: &str, formatted: &str) {
}],
});

fixture.format_doucment(
fixture.format_document(
DocumentFormattingParams {
text_document: TextDocumentIdentifier { uri: uri(1) },
options: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion crates/iwes/tests/go_to_definition_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::fixture::Fixture;
mod fixture;

#[test]
fn no_definiton() {
fn no_definition() {
let fixture = Fixture::new();

fixture.assert_response::<GotoDefinition>(
Expand Down
2 changes: 2 additions & 0 deletions crates/iwes/tests/rename_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use crate::fixture::Fixture;

mod fixture;

// TODO: rename in a sub-directory

#[test]
fn basic_prepare_rename() {
assert_prepare_rename(
Expand Down
6 changes: 3 additions & 3 deletions crates/iwes/tests/sections_to_list_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ fn wrap_list_after_para_with_para_test() {
}

#[test]
fn wrap_list_somehting() {
fn wrap_list_something() {
assert_list(
indoc! {"
# test1
Expand Down Expand Up @@ -147,15 +147,15 @@ fn assert_list(source: &str, line: u32, expected: &str) {
range: Range::new(Position::new(line, 0), Position::new(line, 0)),
context: CodeActionContext {
diagnostics: Default::default(),
only: action_kinds("refactor.rewrite.secton.list"),
only: action_kinds("refactor.rewrite.section.list"),
trigger_kind: None,
},
work_done_progress_params: Default::default(),
partial_result_params: Default::default(),
},
vec![CodeActionOrCommand::CodeAction(CodeAction {
title: "Section to list".to_string(),
kind: action_kind("refactor.rewrite.secton.list"),
kind: action_kind("refactor.rewrite.section.list"),
edit: Some(WorkspaceEdit {
document_changes: Some(DocumentChanges::Operations(vec![
DocumentChangeOperation::Edit(TextDocumentEdit {
Expand Down
4 changes: 2 additions & 2 deletions crates/liwe/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub enum ActionType {
ListToSections, // action for top-level list surrounding cursor
ReferenceInlineSection, // action for reference under cursor
ReferenceInlineQuote, // action for reference under cursor
SectionExtract, // acton for secion under cursor
SectionExtract, // acton for section under cursor
SectionExtractSubsections, // action for section under cursor
SectionToList, // action for section under cursor

Expand All @@ -34,7 +34,7 @@ impl ActionType {
ActionType::ReferenceInlineList => "refactor.inline.reference.list",
ActionType::ReferenceInlineQuote => "refactor.inline.reference.quote",
ActionType::SectionExtractSubsections => "refactor.extract.subsections",
ActionType::SectionToList => "refactor.rewrite.secton.list",
ActionType::SectionToList => "refactor.rewrite.section.list",
ActionType::SectionExtract => "refactor.extract.section",
}
}
Expand Down
11 changes: 9 additions & 2 deletions crates/liwe/src/database.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::HashMap;

use itertools::Itertools;
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};

Expand All @@ -9,9 +11,11 @@ use fuzzy_matcher::{skim::SkimMatcherV2, FuzzyMatcher};

use crate::parser::Parser;

type Documents = HashMap<Key, Content>;

pub struct Database {
graph: Graph,
content: State,
content: Documents,
pub sequential_ids: bool,
paths: Vec<SearchPath>,
}
Expand Down Expand Up @@ -78,7 +82,10 @@ impl Database {
graph,
sequential_ids,
paths,
content: state,
content: state
.iter()
.map(|(k, v)| (Key::from_rel_link_url(k), v.clone()))
.collect(),
}
}

Expand Down
Loading

0 comments on commit 754a660

Please sign in to comment.