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

Commit bf4d9fc

Browse files
0xSwapFeeder0xmemorygrinder
authored andcommitted
wip(solidity/references)
1 parent 19124b5 commit bf4d9fc

File tree

6 files changed

+4052
-17
lines changed

6 files changed

+4052
-17
lines changed

libs/solc-references/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl ReferencesProvider {
2626
for res_file in &ast_files {
2727
let mut found = false;
2828
for file in &mut self.files {
29-
if file.file == res_file.file {
29+
if file.ast.id == res_file.ast.id {
3030
found = true;
3131
file.ast = res_file.ast.clone();
3232
if res_file.src.len() > 0 {
@@ -81,6 +81,7 @@ impl ReferencesProvider {
8181
references.push(location);
8282
}
8383
}
84+
8485
references
8586
}
8687
}

libs/solc-references/src/usages.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ impl UsagesFinder {
8282

8383
pub fn find(&mut self, ast: &SourceUnit) -> Vec<InteractableNode> {
8484
self.visit_source_unit(ast);
85+
eprintln!("Nodes found for file with id {}: ", ast.id);
8586
for node in &self.to_find {
8687
eprintln!("Found REF node: {:?}", node);
8788
}

toolchains/solidity/core/crates/references-server/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ exclude.workspace = true
99
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1010

1111
[dependencies]
12-
tokio = "1.36.0"
12+
tokio = { version = "1.36.0", features = ["full"] }
1313
tower-lsp = "0.20.0"
1414
solc-references = { path = "../../../../../libs/solc-references" }

toolchains/solidity/core/crates/references-server/src/main.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,11 @@ impl LanguageServer for Backend {
8282
position.line += 1;
8383
position.character += 1;
8484
let locations = self.references_provider.lock().await.get_references(solc_references::Position { line: position.line, column: position.character });
85-
let ret: Vec<LspLocation> = locations.iter().map(|location| LspLocation {
86-
uri: uri.clone(),
85+
let ret: Vec<LspLocation> = locations.iter().map(|location| {
86+
let mut new_uri = uri.clone();
87+
new_uri.set_path(&location.uri);
88+
LspLocation {
89+
uri: new_uri,
8790
range: LspRange {
8891
start: LspPosition {
8992
line: location.start.line - 1,
@@ -94,7 +97,7 @@ impl LanguageServer for Backend {
9497
character: location.end.column - 1,
9598
},
9699
},
97-
}).collect();
100+
}}).collect();
98101
Ok(Some(ret))
99102
}
100103

@@ -120,10 +123,12 @@ impl Backend {
120123
}
121124

122125
#[tokio::main]
123-
async fn main() {
124-
let stdin = tokio::io::stdin();
125-
let stdout = tokio::io::stdout();
126+
async fn main() -> tokio::io::Result<()> {
127+
let listener = tokio::net::TcpListener::bind("127.0.0.1:9001").await?;
128+
let (stream, _) = listener.accept().await?;
129+
let (read, write) = tokio::io::split(stream);
126130

127131
let (service, socket) = LspService::new(Backend::new);
128-
Server::new(stdin, stdout, socket).serve(service).await;
132+
Server::new(read, write, socket).serve(service).await;
133+
Ok(())
129134
}

toolchains/solidity/extension/src/references.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,28 @@ import {
55
LanguageClient,
66
LanguageClientOptions,
77
ServerOptions,
8-
TransportKind
8+
TransportKind,
9+
SocketTransport,
10+
StreamInfo
911
} from 'vscode-languageclient/node';
1012
import { TextDecoder } from 'util';
13+
import * as net from 'net';
1114

1215
export async function createReferencesClient(context: ExtensionContext): Promise<LanguageClient> {
13-
// The server is implemented in node
16+
let connectionInfo = {
17+
port: 9001,
18+
host: "127.0.0.1"
19+
};
20+
let serverOptions = () => {
21+
// Connect to language server via socket
22+
let socket = net.connect(connectionInfo);
23+
let result: StreamInfo = {
24+
writer: socket,
25+
reader: socket
26+
};
27+
return Promise.resolve(result);
28+
};
29+
// The server is implemented in node
1430
const serverBinary = context.asAbsolutePath(
1531
path.join(
1632
'dist',
@@ -20,12 +36,9 @@ export async function createReferencesClient(context: ExtensionContext): Promise
2036

2137
// If the extension is launched in debug mode then the debug server options are used
2238
// Otherwise the run options are used
23-
const serverOptions: ServerOptions = {
24-
run: { command: serverBinary, transport: TransportKind.stdio },
25-
debug: {
26-
command: serverBinary,
27-
transport: TransportKind.stdio,
28-
}
39+
const socketOptions: SocketTransport = {
40+
port: 9001,
41+
kind: TransportKind.socket,
2942
};
3043

3144
// Options to control the language client

0 commit comments

Comments
 (0)