Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
wip(solidity/references)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSwapFeeder committed Feb 17, 2024
1 parent dffe6a9 commit e88e818
Show file tree
Hide file tree
Showing 6 changed files with 4,052 additions and 17 deletions.
3 changes: 2 additions & 1 deletion libs/solc-references/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl ReferencesProvider {
for res_file in &ast_files {
let mut found = false;
for file in &mut self.files {
if file.file == res_file.file {
if file.ast.id == res_file.ast.id {
found = true;
file.ast = res_file.ast.clone();
if res_file.src.len() > 0 {
Expand Down Expand Up @@ -81,6 +81,7 @@ impl ReferencesProvider {
references.push(location);
}
}

references
}
}
1 change: 1 addition & 0 deletions libs/solc-references/src/usages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ impl UsagesFinder {

pub fn find(&mut self, ast: &SourceUnit) -> Vec<InteractableNode> {
self.visit_source_unit(ast);
eprintln!("Nodes found for file with id {}: ", ast.id);
for node in &self.to_find {
eprintln!("Found REF node: {:?}", node);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ exclude.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tokio = "1.36.0"
tokio = { version = "1.36.0", features = ["full"] }
tower-lsp = "0.20.0"
solc-references = { path = "../../../../../libs/solc-references" }
19 changes: 12 additions & 7 deletions toolchains/solidity/core/crates/references-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ impl LanguageServer for Backend {
position.line += 1;
position.character += 1;
let locations = self.references_provider.lock().await.get_references(solc_references::Position { line: position.line, column: position.character });
let ret: Vec<LspLocation> = locations.iter().map(|location| LspLocation {
uri: uri.clone(),
let ret: Vec<LspLocation> = locations.iter().map(|location| {
let mut new_uri = uri.clone();
new_uri.set_path(&location.uri);
LspLocation {
uri: new_uri,
range: LspRange {
start: LspPosition {
line: location.start.line - 1,
Expand All @@ -94,7 +97,7 @@ impl LanguageServer for Backend {
character: location.end.column - 1,
},
},
}).collect();
}}).collect();
Ok(Some(ret))
}

Expand All @@ -120,10 +123,12 @@ impl Backend {
}

#[tokio::main]
async fn main() {
let stdin = tokio::io::stdin();
let stdout = tokio::io::stdout();
async fn main() -> tokio::io::Result<()> {
let listener = tokio::net::TcpListener::bind("127.0.0.1:9001").await?;
let (stream, _) = listener.accept().await?;
let (read, write) = tokio::io::split(stream);

let (service, socket) = LspService::new(Backend::new);
Server::new(stdin, stdout, socket).serve(service).await;
Server::new(read, write, socket).serve(service).await;
Ok(())
}
29 changes: 21 additions & 8 deletions toolchains/solidity/extension/src/references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,28 @@ import {
LanguageClient,
LanguageClientOptions,
ServerOptions,
TransportKind
TransportKind,
SocketTransport,
StreamInfo
} from 'vscode-languageclient/node';
import { TextDecoder } from 'util';
import * as net from 'net';

export async function createReferencesClient(context: ExtensionContext): Promise<LanguageClient> {
// The server is implemented in node
let connectionInfo = {
port: 9001,
host: "127.0.0.1"
};
let serverOptions = () => {
// Connect to language server via socket
let socket = net.connect(connectionInfo);
let result: StreamInfo = {
writer: socket,
reader: socket
};
return Promise.resolve(result);
};
// The server is implemented in node
const serverBinary = context.asAbsolutePath(
path.join(
'dist',
Expand All @@ -20,12 +36,9 @@ export async function createReferencesClient(context: ExtensionContext): Promise

// If the extension is launched in debug mode then the debug server options are used
// Otherwise the run options are used
const serverOptions: ServerOptions = {
run: { command: serverBinary, transport: TransportKind.stdio },
debug: {
command: serverBinary,
transport: TransportKind.stdio,
}
const socketOptions: SocketTransport = {
port: 9001,
kind: TransportKind.socket,
};

// Options to control the language client
Expand Down
Loading

0 comments on commit e88e818

Please sign in to comment.