Skip to content

Commit

Permalink
Add comment hovering and fixed various bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
VonTum committed Apr 7, 2024
1 parent 7c04071 commit 10024a3
Show file tree
Hide file tree
Showing 15 changed files with 323 additions and 194 deletions.
3 changes: 2 additions & 1 deletion multiply_add.sus
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,11 @@ module module_taking_a_lot_of_time : int data_in'0 -> int data_out'200 {
}



module good_cycle : int a -> int r {
state int test;
initial test = 0;

int new_test = test + a;
test = new_test;

Expand Down
112 changes: 0 additions & 112 deletions src/ast.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/codegen_fallback.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{iter::zip, ops::Deref};

use crate::{ast::Module, flattening::Instruction, instantiation::{ConnectToPathElem, InstantiatedModule, RealWire, RealWireDataSource, WireID}, linker::{get_builtin_type, TypeUUID}, typing::ConcreteType};
use crate::{flattening::{Instruction, Module}, instantiation::{ConnectToPathElem, InstantiatedModule, RealWire, RealWireDataSource, WireID}, linker::{get_builtin_type, TypeUUID}, typing::ConcreteType};

fn get_type_name_size(id : TypeUUID) -> u64 {
if id == get_builtin_type("int") {
Expand Down
18 changes: 12 additions & 6 deletions src/dev_aid/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use lsp_server::{Connection, Message, Response};
use lsp_types::notification::Notification;

use crate::{
arena_alloc::ArenaVector, ast::{IdentifierType, Module}, errors::{CompileError, ErrorCollector, ErrorLevel}, file_position::{FileText, LineCol, Span}, flattening::{FlatID, Instruction}, instantiation::{SubModuleOrWire, CALCULATE_LATENCY_LATER}, linker::{FileData, FileUUID, FileUUIDMarker, Linker, LocationInfo}, parser::perform_full_semantic_parse, walk_name_color
arena_alloc::ArenaVector, errors::{CompileError, ErrorCollector, ErrorLevel}, file_position::{FileText, LineCol, Span}, flattening::{FlatID, Instruction, IdentifierType, Module}, instantiation::{SubModuleOrWire, CALCULATE_LATENCY_LATER}, linker::{FileData, FileUUID, FileUUIDMarker, Linker, LocationInfo}, parser::perform_full_semantic_parse, walk_name_color
};

use super::syntax_highlighting::IDEIdentifierType;
Expand Down Expand Up @@ -150,6 +150,7 @@ fn get_modifiers_for_token(tok : IDEIdentifierType) -> u32 {
fn from_position(pos : lsp_types::Position) -> LineCol {
LineCol{line : pos.line as usize, col : pos.character as usize}
}
#[allow(dead_code)]
fn from_position_range(range : lsp_types::Range) -> std::ops::Range<LineCol> {
std::ops::Range{start : from_position(range.start), end : from_position(range.end)}
}
Expand Down Expand Up @@ -253,7 +254,7 @@ fn send_errors_warnings(connection: &Connection, errors : ErrorCollector, main_f
Ok(())
}

fn get_hover_info<'l>(file_cache : &'l LoadedFileCache, text_pos : &lsp_types::TextDocumentPositionParams) -> Option<(LocationInfo<'l>, lsp_types::Range)> {
fn get_hover_info<'l>(file_cache : &'l LoadedFileCache, text_pos : &lsp_types::TextDocumentPositionParams) -> Option<(&'l FileData, LocationInfo<'l>, lsp_types::Range)> {
let uuid = file_cache.find_uri(&text_pos.text_document.uri).unwrap();

let file_data = &file_cache.linker.files[uuid];
Expand All @@ -264,7 +265,7 @@ fn get_hover_info<'l>(file_cache : &'l LoadedFileCache, text_pos : &lsp_types::T
//let span = Span::new_single_token(token_idx);

let char_line_range = file_data.file_text.get_span_linecol_range(span);
Some((info, to_position_range(char_line_range)))
Some((file_data, info, to_position_range(char_line_range)))
}

fn push_all_errors(connection: &Connection, file_cache : &LoadedFileCache) -> Result<(), Box<dyn Error + Sync + Send>> {
Expand Down Expand Up @@ -357,9 +358,9 @@ fn handle_request(method : &str, params : serde_json::Value, file_cache : &mut L
request::HoverRequest::METHOD => {
let params : HoverParams = serde_json::from_value(params).expect("JSON Encoding Error while parsing params");
println!("HoverRequest");

file_cache.ensure_contains_file(&params.text_document_position_params.text_document.uri);
serde_json::to_value(&if let Some((info, range)) = get_hover_info(&file_cache, &params.text_document_position_params) {
serde_json::to_value(&if let Some((file_data, info, range)) = get_hover_info(&file_cache, &params.text_document_position_params) {
let mut hover_list : Vec<MarkedString> = Vec::new();
if debug {
hover_list.push(MarkedString::String(format!("{info:?}")))
Expand All @@ -371,6 +372,7 @@ fn handle_request(method : &str, params : serde_json::Value, file_cache : &mut L
let name_str = &decl.name;

let identifier_type_keyword = decl.identifier_type.get_keyword();
hover_list.push(MarkedString::String(decl.documentation.to_string(&file_data.file_text)));
hover_list.push(MarkedString::String(format!("{identifier_type_keyword} {typ_str} {name_str}")));

gather_hover_infos(md, decl_id, decl.identifier_type.is_generative(), file_cache, &mut hover_list);
Expand All @@ -386,6 +388,9 @@ fn handle_request(method : &str, params : serde_json::Value, file_cache : &mut L
hover_list.push(MarkedString::String(typ.to_type().to_string(&file_cache.linker.types)));
}
LocationInfo::Global(global) => {
if let Some(link_info) = file_cache.linker.get_link_info(global) {
hover_list.push(MarkedString::String(link_info.documentation.to_string(&file_data.file_text)));
}
hover_list.push(MarkedString::String(file_cache.linker.get_full_name(global)));
}
};
Expand All @@ -400,7 +405,7 @@ fn handle_request(method : &str, params : serde_json::Value, file_cache : &mut L
println!("GotoDefinition");

file_cache.ensure_contains_file(&params.text_document_position_params.text_document.uri);
serde_json::to_value(&if let Some((info, _range)) = get_hover_info(&file_cache, &params.text_document_position_params) {
serde_json::to_value(&if let Some((_file_data, info, _range)) = get_hover_info(&file_cache, &params.text_document_position_params) {
match info {
LocationInfo::WireRef(md, decl_id) => {
let uri = file_cache.uris[md.link_info.file].clone();
Expand Down Expand Up @@ -441,6 +446,7 @@ fn handle_request(method : &str, params : serde_json::Value, file_cache : &mut L
/*request::DocumentHighlightRequest::METHOD => {
let params : DocumentHighlightParams = serde_json::from_value(params).expect("JSON Encoding Error while parsing params");
file_cache.ensure_contains_file(&params.text_document_position_params.text_document.uri);
if let Some((hover_info, span)) = get_hover_info(file_cache, &params.text_document_position_params) {
}
Expand Down
2 changes: 1 addition & 1 deletion src/dev_aid/syntax_highlighting.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

use std::{ops::Range, path::PathBuf};

use crate::{arena_alloc::ArenaVector, ast::*, errors::{CompileError, ErrorLevel}, file_position::Span, flattening::{Instruction, WireSource}, linker::{FileUUID, FileUUIDMarker, Linker, NameElem}, parser::*};
use crate::{arena_alloc::ArenaVector, errors::{CompileError, ErrorLevel}, file_position::Span, flattening::{IdentifierType, Instruction, WireSource}, linker::{FileUUID, FileUUIDMarker, Linker, NameElem}, parser::*};

use ariadne::*;

Expand Down
1 change: 1 addition & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub struct ErrorCollector {
file_len : usize, // Only used for debugging, to see no invalid errors are produced
}

#[allow(dead_code)]
impl ErrorCollector {
pub fn new(file : FileUUID, file_len : usize) -> Self {
Self{errors : RefCell::new(Vec::new()), file, file_len, did_error : Cell::new(false)}
Expand Down
2 changes: 2 additions & 0 deletions src/file_position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ impl Display for Span {
#[derive(Clone,Copy,Debug,PartialEq,Eq,Hash)]
pub struct BracketSpan(Span);

#[allow(dead_code)]
impl BracketSpan {
pub fn from_outer(span : Span) -> Self {Self(span)}
pub fn inner_span(&self) -> Span {
Expand Down Expand Up @@ -145,6 +146,7 @@ impl FileText {
self.byte_to_linecol(span.0)..self.byte_to_linecol(span.1)
}

#[allow(dead_code)]
pub fn whole_file_span(&self) -> Span {
Span(0, self.file_text.len())
}
Expand Down
Loading

0 comments on commit 10024a3

Please sign in to comment.