Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Files #23

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added final code
  • Loading branch information
NoelCGregory committed Jan 8, 2024
commit 3054254a0a1f13dd0225041d5813a6840ff638db
84 changes: 51 additions & 33 deletions ls_framework/src/features/hover.rs
Original file line number Diff line number Diff line change
@@ -13,46 +13,64 @@ pub fn get_hover_info(
position: Position,

) -> Option<HoverContents> {
info!("Hover");
let ast_query = ast_query.lock().unwrap();
let root_visit = ast_query.visit_root();
let node = root_visit.get_node_at_position(position)?;
let previous_name = &node.get().content;
let n = node.get().linked_symbol.clone()?;

let y = graph.get_node(n.file_id).unwrap().clone();
let cur_url = y.file.uri.clone();
let x = y.file.symbol_table_manager.lock().unwrap();

let binding = x.get_all_symbols();
//binding.iter().for_each(|s| info!("T:{:?}",&s.get_name()));
let symbol_exist = binding.iter().find(|s| &s.get_name() == previous_name);

info!("Symbollldfddyy{:?} ",symbol_exist);
let temp = { let st_query = symbol_table_query.lock().unwrap();
let symbol = st_query.get_symbol(node.get().linked_symbol.clone()?)?;
symbol.get_type_symbol()
};

if let Some(temp1) = temp {
let st_query = symbol_table_query.lock().unwrap();
let symbol = st_query.get_symbol(node.get().linked_symbol.clone()?)?;
info!("Sylinkedmbol:{:?}",node.get().linked_symbol.clone().unwrap());

info!("Symbol:{}",symbol);

let mut type_name = String::from("");

info!("Temp Hover");
let type_symbol = st_query.get_symbol(temp1)?;
Some(HoverContents::Scalar(MarkedString::String(format!(
"{}: {}",
symbol.get_name(),
type_symbol.get_name()
))))
} else {
info!("Added Hover");
let previous_name = &node.get().content;
let linked_symbol = node.get().linked_symbol.clone()?;

info!("A");

let mut symbol_name = String::from("");
if let Some(symbol) = symbol_exist{
info!("Symbollldfddyydddd{:?} ",symbol);
info!("prev:{:?}",previous_name);
let linked_node = graph.get_node(linked_symbol.file_id).unwrap().clone();
info!("A1");

symbol_name = symbol.get_name();
if let Some(symbol_type) = symbol.get_type_symbol(){
let type_symbol = x.get_symbol(symbol_type).unwrap();

info!("Symbofffl type: {}",type_symbol);
type_name=type_symbol.get_name();
info!("Symbol type: {}",type_symbol);
}
}

info!("preve:{:?}",linked_node);
let linked_manager = linked_node.file.symbol_table_manager.lock().unwrap();
info!("A2");
let binding = linked_manager.get_all_symbols();
info!("A3");

info!("list {:?}",binding);
let symbol_exist = binding.iter().find(|s| &s.get_name() == previous_name);
info!("A4");
info!("{:?}",symbol_exist);
let symbol = symbol_exist?;
info!("A5");
info!("{:?}",symbol);
info!("{:?}",symbol.get_type_symbol().clone().unwrap());
let type_symbol = linked_manager.get_symbol(symbol.get_type_symbol()?)?;

Some(HoverContents::Scalar(MarkedString::String(format!(
"{}: {}",
symbol.get_name(),
type_symbol.get_name()
))))


info!("Symbol name type: {}",type_name);
Some(HoverContents::Scalar(MarkedString::String(format!(
"{}: {}",
symbol_name,
type_name
))))
}


}
2 changes: 1 addition & 1 deletion ls_framework/src/features/semantic_tokens.rs
Original file line number Diff line number Diff line change
@@ -81,7 +81,6 @@ pub fn get_tokens(
tokens.extend(temp_array); //concating two vectors
temp_array = Vec::new();
}

temp_array.push(SemanticToken {
delta_line: line as u32,
delta_start: item.start,
@@ -91,6 +90,7 @@ pub fn get_tokens(
});
}

info!("Final: {:?}",tokens);
SemanticTokensResult::Tokens(SemanticTokens {
result_id: None,
data: tokens,
20 changes: 2 additions & 18 deletions ls_framework/src/language_server.rs
Original file line number Diff line number Diff line change
@@ -34,15 +34,6 @@ impl Backend {
impl LanguageServer for Backend {
async fn initialize(&self, params: InitializeParams) -> Result<InitializeResult> {
let workspace_url = &params.workspace_folders.unwrap()[0].uri.to_string();
/*self.workspace
.write()
.unwrap()
.read_local_files(&workspace_url);*/
info!("Started Reading");
/* self.workspace
.write()
.unwrap()
.read_external_files();*/

let log_file_path = env::temp_dir().join(format!(
"{}-lsf.log",
@@ -67,20 +58,13 @@ impl LanguageServer for Backend {
.await;
}
}
info!("dd lsp");

std::panic::set_hook(Box::new(|info| {
error!("{info}");
}));
/*self.workspace
.write()
.unwrap()
.read_local_files(&workspace_url);*/
info!("Started Reading");
/* self.workspace
self.workspace
.write()
.unwrap()
.read_external_files();*/
.read_local_files(&workspace_url);
info!("Read lsp");

info!("Initializing lsp");
6 changes: 1 addition & 5 deletions ls_framework/src/metadata/symbol_table.rs
Original file line number Diff line number Diff line change
@@ -435,7 +435,7 @@ impl SymbolTable {
}
}
}
pub fn parse_types(&mut self, root_id: NodeId, ast_arena: &mut Arena<Node>) {
fn parse_types(&mut self, root_id: NodeId, ast_arena: &mut Arena<Node>) {
for node_id in root_id.descendants(ast_arena) {
if let language_def::Symbol::Init {
kind: _,
@@ -473,10 +473,6 @@ impl SymbolTable {
.linked_symbol
.clone()
{
info!("Added Type");

info!("Added d {:?}",symbol_id);

self.get_symbol_mut(name_symbol_id)
.unwrap()
.set_type_symbol(symbol_id);
25 changes: 7 additions & 18 deletions ls_framework/src/workspace.rs
Original file line number Diff line number Diff line change
@@ -37,36 +37,27 @@ impl Workspace {
info!("Reading local");
let file_extension = "p4";
let mut file_map: HashMap<Url, &str> = HashMap::new();
info!("{}",workspace_addr.clone());
// Parse the URL
let url = Url::parse(&String::from(r"C:\Users\Noel LAPTOP\Downloads\tutorials-master\tutorials-master\exercises\basic")).expect("Failed to parse URL");

let url = Url::parse(workspace_addr).expect("Failed to parse URL");

// Extract the path part of the URL
let url_path = url.path();

info!("{}",url_path);
// Convert the URL path to a Path object
let path = Path::new(url_path);
let walker = WalkDir::new(path).into_iter();

info!("ddddd");
for entry in walker {
info!("Runnifddffdfdfdng");
if let Ok(entry) = entry {
info!("Running");
let path = entry.path();
info!("{:?}",path);

let path_as_string = path.to_string_lossy().to_string();
info!("{}",path_as_string);

if path.extension().unwrap_or_default() == file_extension {
//info!("Stuff {:?}", path.canonicalize().unwrap().display());
let temp = Url::from_file_path(path.canonicalize().unwrap().as_path());
let file_contents = fs::read_to_string(entry.path())?;
info!("{}",temp.clone().unwrap().to_string());
info!("Added {}",temp.clone().unwrap().to_string());
self.add_file(temp.unwrap(), &file_contents.as_str())
}
} else {
//info!("Error");
}
}
Ok(())
@@ -98,11 +89,9 @@ impl Workspace {
Ok(())
}
pub fn add_file(&mut self, url: Url, content: &str) {
info!("Added File1");
let tree = self.parser.parse(content, None);
let index = self.graph.get_next_node_index();
info!("info :{:?}",index);
info!("infto :{:?}",tree.clone().unwrap());
info!("Added File :{:?}",url);

self.graph.add_node(
url.to_string().clone(),
@@ -124,7 +113,7 @@ impl Workspace {
let file = &self.graph.get_node(file_id1.unwrap()).unwrap().file;
info!("File Id {:?}",file_id1);

let (range,file_id) = file.get_definition_location(symbol_position,&self.graph).unwrap();
let (range,file_id) = file.get_definition_location(symbol_position,&self.graph)?;
let uri = &self.graph.get_node(file_id).unwrap().file.uri;
info!("uri:{:?}",uri);
Some(Location::new(uri.clone(), range))