Skip to content

Commit

Permalink
return const value alongside other info
Browse files Browse the repository at this point in the history
  • Loading branch information
x87 committed Nov 30, 2023
1 parent a22447a commit 41472cd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/language_service/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ pub enum SymbolType {
Label = 3,
ModelName = 4,
}
pub struct SymbolInfo {
pub line_number: u32,
pub _type: SymbolType,
pub value: Option<String>,
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct SymbolInfo {
pub struct SymbolInfoRaw {
pub line_number: u32,
pub _type: SymbolType,
pub value: PChar,
}

pub struct DocumentInfo {
Expand Down Expand Up @@ -116,13 +122,15 @@ pub unsafe extern "C" fn language_service_find(
server: *mut LanguageServer,
symbol: PChar,
handle: EditorHandle,
out_value: *mut SymbolInfo,
out_value: *mut SymbolInfoRaw,
) -> bool {
boolclosure! {{
let server = server.as_mut()?;
let s = server.find(pchar_to_str(symbol)?, handle)?;
out_value.as_mut()?._type = s._type;
out_value.as_mut()?.line_number = s.line_number;
let out_value = out_value.as_mut()?;
out_value._type = s._type;
out_value.line_number = s.line_number;
out_value.value = CString::new(s.value.unwrap_or_default()).unwrap().into_raw();
Some(())
}}
}
Expand Down
3 changes: 3 additions & 0 deletions src/language_service/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,15 @@ impl LanguageServer {
let table = st.get(&handle)?;
let map = table.symbols.get(&symbol.to_ascii_lowercase())?;
Some(SymbolInfo {
// if file_name is None, then it's a symbol from the opened document, use actual line number
// otherwise it's a symbol from $include, use 0 as line number
line_number: if map.file_name.is_some() {
0
} else {
map.line_number
},
_type: map._type,
value: map.value.clone(),
})
}

Expand Down

0 comments on commit 41472cd

Please sign in to comment.