Skip to content

Commit c55e416

Browse files
committed
feat: add logging instrumentation to LSP server and GUI
1 parent ce6512b commit c55e416

File tree

17 files changed

+237
-96
lines changed

17 files changed

+237
-96
lines changed

Cargo.lock

Lines changed: 63 additions & 64 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ lrlex = "0.13"
2424
lrpar = "0.13"
2525
bytes = "1"
2626
futures = "0.3"
27+
tracing = "0.1"
28+
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
29+
tracing-appender = "0.2"
2730

2831
geometry = { version = "0.7", registry = "substrate" }
2932
enumify = { version = "0.2", registry = "substrate" }

README.md

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ in both Neovim and the GUI.
7171
To use VS Code as your code editor, you will additionally need:
7272
- [Node JS (tested on 25.0.0)](https://nodejs.org/en/download)
7373

74-
First, open your VS Code user settings using Command Palette > Preferences: Open User Settings (JSON).
74+
First, open your VS Code user settings using `Command Palette > Preferences: Open User Settings (JSON)`.
7575
Add the following key:
7676

7777
```json
@@ -107,7 +107,7 @@ With this alias defined, you can now run:
107107
codear core/compiler/examples/argon_workspace
108108
```
109109

110-
Open the `lib.ar` file within the workspace. You can then start the GUI by running Command Palette > Argon LSP: Start GUI.
110+
Open the `lib.ar` file within the workspace. You can then start the GUI by running `Command Palette > Argon LSP: Start GUI`.
111111

112112
> [!WARNING]
113113
> If you cannot find the command for starting the GUI but did not notice any obvious errors, you may be on an old version of VS Code.
@@ -202,6 +202,47 @@ After saving, try opening this cell from the GUI by running `:openCell triple_re
202202
should be able to constrain the instances relative to one another based on their
203203
constituent rectangles.
204204

205+
## Logs
206+
207+
<!-- TODO: Implement commands to open GUI log -->
208+
Argon writes log messages to `~/.local/state/argon/lsp.log` (LSP server) and `~/local/state/argon/gui.log` (GUI).
209+
Log level can be set using the `ARGON_LOG` environment variable
210+
or in editor-specific configuration. If no configuration is specified, only errors will be logged.
211+
Log level configuration follows [`RUST_LOG`](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/index.html#filtering-events-with-environment-variables) syntax.
212+
213+
For performance, it is recommended to use `ARGON_LOG=warn` or `ARGON_LOG=error` unless you are troubleshooting an issue.
214+
215+
### Neovim
216+
217+
While the LSP is running, you can open the LSP logs using the `:ArgonLsp log` command
218+
219+
To configure the log level, you can use the `vim.g.argon_lsp.log.level` key:
220+
221+
```lua
222+
vim.g.argon_lsp = {
223+
-- ...
224+
log = {
225+
level = "debug"
226+
}
227+
}
228+
```
229+
230+
The Neovim plugin will supply `ARGON_LOG=debug` when starting the LSP server and GUI.
231+
232+
### VS Code
233+
234+
While the LSP is running, you can open the LSP logs using the `Command Palette > Argon LSP: Open Log` command.
235+
236+
To configure the log level, you can use the `argonLsp.log.level` key:
237+
238+
```json
239+
{
240+
"argonLsp.log.level": "debug"
241+
}
242+
```
243+
244+
The VS Code plugin will supply `ARGON_LOG=debug` when starting the LSP server and GUI.
245+
205246
## Contributing
206247

207248
If you'd like to contribute to Argon, please let us know. You can:
@@ -213,7 +254,7 @@ Documentation updates, tests, and bugfixes are always welcome.
213254
For larger feature additions, please discuss your ideas with us before implementing them.
214255

215256
Contributions can be submitted by opening a pull request against the `main` branch
216-
of this repository.
257+
of this repository. Developer documentation can be found in the [`docs/`](docs/developers.md) folder.
217258

218259
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion
219260
in the work by you shall be licensed under the BSD 3-Clause license, without any additional terms or conditions.

core/gui/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ indexmap = { workspace = true }
2626
rgb = { version = "0.8", features = ["serde"] }
2727
unicode-segmentation = "1"
2828
tower-lsp = "0.20"
29+
tracing = { workspace = true }
30+
tracing-subscriber = { workspace = true }
31+
tracing-appender = { workspace = true }

core/gui/src/editor/input.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,6 @@ impl Render for TextInput {
665665
.track_focus(&self.focus_handle(cx))
666666
.cursor(CursorStyle::IBeam)
667667
.on_action(cx.listener(move |input, _: &EditDim, _window, cx| {
668-
println!("test");
669668
if let ToolState::EditDim(EditDimToolState { original_value, .. }) =
670669
input.state.read(cx).tool.read(cx)
671670
{

core/gui/src/editor/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ impl Editor {
339339
let tool_bar = cx.new(|_cx| ToolBar::new(&state));
340340
let canvas_focus_handle = cx.focus_handle();
341341
let text_input_focus_handle = cx.focus_handle();
342-
println!("{canvas_focus_handle:?}");
343342
window.focus(&canvas_focus_handle);
344343
let canvas = cx.new(|cx| {
345344
LayoutCanvas::new(

core/gui/src/lib.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ use std::{borrow::Cow, net::SocketAddr};
44
use clap::Parser;
55
use editor::Editor;
66
use gpui::*;
7+
use lsp_server::config::default_argon_home;
8+
use tracing::info;
9+
use tracing_subscriber::EnvFilter;
710

811
use crate::actions::*;
912
use crate::assets::{ZED_PLEX_MONO, ZED_PLEX_SANS};
@@ -50,6 +53,15 @@ impl AssetSource for Assets {
5053
pub fn main() {
5154
let args = Args::parse();
5255

56+
// TODO: Allow configuration via ARGON_HOME environment variable.
57+
if let Some(log_dir) = default_argon_home() {
58+
tracing_subscriber::fmt()
59+
.with_env_filter(EnvFilter::from_env("ARGON_LOG"))
60+
.with_writer(tracing_appender::rolling::never(log_dir, "gui.log"))
61+
.with_ansi(false)
62+
.init();
63+
}
64+
5365
Application::new()
5466
.with_assets(Assets {
5567
base: PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("assets"),
@@ -151,6 +163,6 @@ pub fn main() {
151163

152164
// Define the quit function that is registered with the App
153165
fn quit(_: &Quit, cx: &mut App) {
154-
println!("Gracefully quitting the application . . .");
166+
info!("Gracefully quitting the application . . .");
155167
cx.quit();
156168
}

core/lsp-server/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ lrlex = { workspace = true }
1818
lrpar = { workspace = true }
1919
itertools = { workspace = true }
2020
tarpc = { workspace = true }
21-
env_logger = "0.11"
22-
log = "0.4"
2321
lsp-document = "0.6"
2422
arcstr = { workspace = true }
2523
indexmap = { workspace = true }
24+
tracing = { workspace = true }
25+
tracing-subscriber = { workspace = true }
26+
tracing-appender = { workspace = true }

core/lsp-server/src/config.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use std::path::PathBuf;
2+
3+
#[cfg(windows)]
4+
fn home_dir() -> Option<PathBuf> {
5+
env::var_os("USERPROFILE")
6+
.filter(|s| !s.is_empty())
7+
.map(PathBuf::from)
8+
.or_else(home_dir_crt)
9+
}
10+
#[cfg(unix)]
11+
fn home_dir() -> Option<PathBuf> {
12+
std::env::home_dir()
13+
}
14+
15+
// TODO: Allow configuration via ARGON_HOME environment variable.
16+
pub fn default_argon_home() -> Option<PathBuf> {
17+
Some(home_dir()?.join(".local/state/argon"))
18+
}

0 commit comments

Comments
 (0)