@@ -5,10 +5,7 @@ use crate::utils::*;
55use std:: sync:: Arc ;
66use tokio:: sync:: Mutex ;
77use tower_lsp:: jsonrpc:: Result ;
8- use tower_lsp:: lsp_types;
98use tower_lsp:: lsp_types:: * ;
10- use tower_lsp:: lsp_types:: Position as LspPosition ;
11- use tower_lsp:: lsp_types:: Range as LspRange ;
129use tower_lsp:: lsp_types:: Location as LspLocation ;
1310use tower_lsp:: { Client , LanguageServer , LspService , Server } ;
1411use solc_references:: * ;
@@ -59,21 +56,15 @@ impl LanguageServer for Backend {
5956 self . client
6057 . log_message ( MessageType :: INFO , "osmium-solidity-references initialized!" )
6158 . await ;
62- let current_time = std:: time:: SystemTime :: now ( ) ;
6359 if let Err ( e) = self . references_provider . lock ( ) . await . update_file_content ( ) {
6460 self . client . log_message ( MessageType :: ERROR , format ! ( "Error updating file content: {}" , e) ) . await ;
6561 }
66- let elapsed = current_time. elapsed ( ) . unwrap ( ) ;
67- self . client . log_message ( MessageType :: INFO , format ! ( "Finished updating ast in: {:?} seconds" , elapsed) ) . await ;
6862 }
6963
7064 async fn did_save ( & self , _: DidSaveTextDocumentParams ) {
71- let current_time = std:: time:: SystemTime :: now ( ) ;
7265 if let Err ( e) = self . references_provider . lock ( ) . await . update_file_content ( ) {
7366 self . client . log_message ( MessageType :: ERROR , format ! ( "Error updating file content: {}" , e) ) . await ;
7467 }
75- let elapsed = current_time. elapsed ( ) . unwrap ( ) ;
76- self . client . log_message ( MessageType :: INFO , format ! ( "Finished updating ast in: {:?} seconds" , elapsed) ) . await ;
7768 }
7869
7970 async fn references ( & self , params : ReferenceParams ) -> Result < Option < Vec < LspLocation > > > {
@@ -82,23 +73,13 @@ impl LanguageServer for Backend {
8273 let mut position = params. text_document_position . position ;
8374 position. line += 1 ;
8475 position. character += 1 ;
76+
8577 let locations = self . references_provider . lock ( ) . await . get_references ( & normalize_path ( uri. path ( ) ) , solc_references:: Position { line : position. line , column : position. character } ) ;
8678 let ret: Vec < LspLocation > = locations. iter ( ) . map ( |location| {
8779 let mut new_uri = uri. clone ( ) ;
8880 new_uri. set_path ( & escape_path ( & location. uri ) ) ;
89- LspLocation {
90- uri : new_uri,
91- range : LspRange {
92- start : LspPosition {
93- line : location. start . line - 1 ,
94- character : location. start . column - 1 ,
95- } ,
96- end : LspPosition {
97- line : location. end . line - 1 ,
98- character : location. end . column - 1 ,
99- } ,
100- } ,
101- } } ) . collect ( ) ;
81+ location_to_lsp_location ( & new_uri, & location)
82+ } ) . collect ( ) ;
10283 Ok ( Some ( ret) )
10384 }
10485
@@ -108,22 +89,12 @@ impl LanguageServer for Backend {
10889 let mut position = params. text_document_position_params . position ;
10990 position. line += 1 ;
11091 position. character += 1 ;
92+
11193 let location = self . references_provider . lock ( ) . await . get_definition ( & normalize_path ( uri. path ( ) ) , solc_references:: Position { line : position. line , column : position. character } ) ;
94+
11295 if let Some ( location) = location {
11396 uri. set_path ( & escape_path ( & location. uri ) ) ;
114- return Ok ( Some ( GotoDefinitionResponse :: Scalar ( lsp_types:: Location {
115- uri : uri,
116- range : LspRange {
117- start : LspPosition {
118- line : location. start . line - 1 ,
119- character : location. start . column - 1 ,
120- } ,
121- end : LspPosition {
122- line : location. end . line - 1 ,
123- character : location. end . column - 1 ,
124- } ,
125- } ,
126- } ) ) ) ;
97+ return Ok ( Some ( GotoDefinitionResponse :: Scalar ( location_to_lsp_location ( & uri, & location) ) ) ) ;
12798 }
12899 self . client . log_message ( MessageType :: INFO , "No definition found" ) . await ;
129100 Ok ( None )
@@ -140,12 +111,21 @@ impl Backend {
140111}
141112
142113#[ tokio:: main]
143- async fn main ( ) -> tokio:: io:: Result < ( ) > {
114+ async fn main ( ) {
115+ /*
116+
117+ USE THIS CODE TO DEBUG
118+
144119 let listener = tokio::net::TcpListener::bind("127.0.0.1:9001").await?;
145120 let (stream, _) = listener.accept().await?;
146121 let (read, write) = tokio::io::split(stream);
122+ Server::new(read, write, socket).serve(service).await;
123+ */
147124
148125 let ( service, socket) = LspService :: new ( Backend :: new) ;
149- Server :: new ( read, write, socket) . serve ( service) . await ;
150- Ok ( ( ) )
126+ let stdin = tokio:: io:: stdin ( ) ;
127+ let stdout = tokio:: io:: stdout ( ) ;
128+ Server :: new ( stdin, stdout, socket) . serve ( service) . await ;
129+
130+ //Ok(())
151131}
0 commit comments