Skip to content

Commit

Permalink
cut down on argument counts to functions, re-enable lint
Browse files Browse the repository at this point in the history
  • Loading branch information
WillLillis committed Oct 28, 2024
1 parent 244fda6 commit 7e4e40b
Show file tree
Hide file tree
Showing 23 changed files with 238 additions and 249 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ items_after_statements = "allow"
cast_possible_truncation = "allow"
module_name_repetitions = "allow"
too_many_lines = "allow"
too_many_arguments = "allow"
similar_names = "allow"

# Taken from tree-sitter's `Cargo.toml`
Expand Down
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ created for different sub-directories or files within your project as `project`s
Source files not contained within any `project` configs will use the default configuration
if provided.

#### NOTE:
#### NOTE

If the server reads in an invalid configuration file, it will display an error
message and exit.
Expand Down Expand Up @@ -101,19 +101,21 @@ compile_flags_txt = [
```

Valid options for the `instruction_set` field include:
- ``"x86"``
- ``"x86-64"``
- ``"x86/x86-64"`` (Enable both)
- ``"arm"``
- ``"arm64"``
- ``"riscv"``
- ``"z80"``

- `"x86"`
- `"x86-64"`
- `"x86/x86-64"` (Enable both)
- `"arm"`
- `"arm64"`
- `"riscv"`
- `"z80"`

Valid options for the `assembler` field include:
- ``"gas"``
- ``"go"``
- ``"masm"``
- ``"nasm"``

- `"gas"`
- `"go"`
- `"masm"`
- `"nasm"`

Don't see an architecture and/or assembler that you'd like to work with? File an
[issue](https://github.com/bergercookie/asm-lsp/issues/new/choose)! We would be
Expand Down
71 changes: 24 additions & 47 deletions asm-lsp/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use asm_lsp::handle::{
};
use asm_lsp::{
get_compile_cmd_for_path, get_compile_cmds, get_completes, get_include_dirs, get_root_config,
Arch, Assembler, NameToInfoMaps, RootConfig, TreeStore,
CompletionItems, DocumentStore, NameToInfoMaps, RootConfig,
};

use compile_commands::{CompilationDatabase, SourceFile};
Expand All @@ -26,16 +26,15 @@ use lsp_types::request::{
References, SignatureHelpRequest,
};
use lsp_types::{
CompletionItem, CompletionItemKind, CompletionOptions, CompletionOptionsCompletionItem,
DiagnosticOptions, DiagnosticServerCapabilities, HoverProviderCapability, InitializeParams,
OneOf, PositionEncodingKind, ServerCapabilities, SignatureHelpOptions,
TextDocumentSyncCapability, TextDocumentSyncKind, WorkDoneProgressOptions,
CompletionItemKind, CompletionOptions, CompletionOptionsCompletionItem, DiagnosticOptions,
DiagnosticServerCapabilities, HoverProviderCapability, InitializeParams, OneOf,
PositionEncodingKind, ServerCapabilities, SignatureHelpOptions, TextDocumentSyncCapability,
TextDocumentSyncKind, WorkDoneProgressOptions,
};

use anyhow::Result;
use log::{error, info};
use lsp_server::{Connection, Message, Notification, Request, RequestId};
use lsp_textdocument::TextDocuments;

/// Entry point of the server. Connects to the client, loads documentation resources,
/// and then enters the main loop
Expand Down Expand Up @@ -154,15 +153,16 @@ pub fn main() -> Result<()> {
}

// Use the maps we populated above to generate completion items
let instr_completion_items = get_completes(
let mut completion_items = CompletionItems::new();
completion_items.instructions = get_completes(
&names_to_info.instructions,
Some(CompletionItemKind::OPERATOR),
);

let reg_completion_items =
completion_items.registers =
get_completes(&names_to_info.registers, Some(CompletionItemKind::VARIABLE));

let directive_completion_items = get_completes(
completion_items.directives = get_completes(
&names_to_info.directives,
Some(CompletionItemKind::OPERATOR),
);
Expand All @@ -175,9 +175,7 @@ pub fn main() -> Result<()> {
&connection,
&config,
&names_to_info,
&instr_completion_items,
&directive_completion_items,
&reg_completion_items,
&completion_items,
&compile_cmds,
&include_dirs,
)?;
Expand All @@ -191,18 +189,17 @@ pub fn main() -> Result<()> {
Ok(())
}

// TODO: Wrap up all the completion items into a struct

fn main_loop(
connection: &Connection,
config: &RootConfig,
names_to_info: &NameToInfoMaps,
instruction_completion_items: &[(Arch, CompletionItem)],
directive_completion_items: &[(Assembler, CompletionItem)],
register_completion_items: &[(Arch, CompletionItem)],
completion_tiems: &CompletionItems,
compile_cmds: &CompilationDatabase,
include_dirs: &HashMap<SourceFile, Vec<PathBuf>>,
) -> Result<()> {
let mut text_store = TextDocuments::new();
let mut tree_store = TreeStore::new();
let mut doc_store = DocumentStore::new();

info!("Starting asm-lsp loop...");
for msg in &connection.receiver {
Expand All @@ -219,8 +216,7 @@ fn main_loop(
id,
config.get_config(&params.text_document_position_params.text_document.uri),
&params,
&text_store,
&mut tree_store,
&mut doc_store,
names_to_info,
include_dirs,
)?;
Expand All @@ -234,11 +230,8 @@ fn main_loop(
id,
&params,
config.get_config(&params.text_document_position.text_document.uri),
&text_store,
&mut tree_store,
instruction_completion_items,
directive_completion_items,
register_completion_items,
&mut doc_store,
completion_tiems,
)?;
info!(
"Completion request serviced in {}ms",
Expand All @@ -250,8 +243,7 @@ fn main_loop(
id,
&params,
config.get_config(&params.text_document_position_params.text_document.uri),
&text_store,
&mut tree_store,
&mut doc_store,
)?;
info!(
"Goto definition request serviced in {}ms",
Expand All @@ -263,8 +255,7 @@ fn main_loop(
id,
&params,
config.get_config(&params.text_document.uri),
&text_store,
&mut tree_store,
&mut doc_store,
)?;
info!(
"Document symbols request serviced in {}ms",
Expand All @@ -276,8 +267,7 @@ fn main_loop(
id,
&params,
config.get_config(&params.text_document_position_params.text_document.uri),
&text_store,
&mut tree_store,
&mut doc_store,
&names_to_info.instructions,
)?;
info!(
Expand All @@ -290,8 +280,7 @@ fn main_loop(
id,
&params,
config.get_config(&params.text_document_position.text_document.uri),
&text_store,
&mut tree_store,
&mut doc_store,
)?;
info!(
"References request serviced in {}ms",
Expand Down Expand Up @@ -331,31 +320,19 @@ fn main_loop(
}
Message::Notification(notif) => {
if let Ok(params) = cast_notif::<DidOpenTextDocument>(notif.clone()) {
handle_did_open_text_document_notification(
&params,
&mut text_store,
&mut tree_store,
);
handle_did_open_text_document_notification(&params, &mut doc_store);
info!(
"Did open text document notification serviced in {}ms",
start.elapsed().as_millis()
);
} else if let Ok(params) = cast_notif::<DidChangeTextDocument>(notif.clone()) {
handle_did_change_text_document_notification(
&params,
&mut text_store,
&mut tree_store,
)?;
handle_did_change_text_document_notification(&params, &mut doc_store)?;
info!(
"Did change text document notification serviced in {}ms",
start.elapsed().as_millis()
);
} else if let Ok(params) = cast_notif::<DidCloseTextDocument>(notif.clone()) {
handle_did_close_text_document_notification(
&params,
&mut text_store,
&mut tree_store,
);
handle_did_close_text_document_notification(&params, &mut doc_store);
info!(
"Did close text document notification serviced in {}ms",
start.elapsed().as_millis()
Expand Down
Loading

0 comments on commit 7e4e40b

Please sign in to comment.