Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a feature flag to disable printlns in kcl-lib for the lsp #2712

Merged
merged 8 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/cargo-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
on:
push:
branches:
- main
paths:
- '**/Cargo.toml'
- '**/Cargo.lock'
- '**/rust-toolchain.toml'
- '**.rs'
- .github/workflows/cargo-check.yml
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
name: cargo check
jobs:
cargocheck:
name: cargo check
runs-on: ubuntu-latest
strategy:
matrix:
dir: ['src/wasm-lib']
steps:
- uses: actions/checkout@v4
- name: Install latest rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true

- name: Rust Cache
uses: Swatinem/[email protected]

- name: Run check
run: |
cd "${{ matrix.dir }}"
# We specifically want to test the disable-println feature
# Since it is not enabled by default, we need to specify it
# This is used in kcl-lsp
cargo check --all --features disable-println --features pyo3
2 changes: 1 addition & 1 deletion .github/workflows/cargo-clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
- name: Run clippy
run: |
cd "${{ matrix.dir }}"
cargo clippy --all --tests --all-features --benches -- -D warnings
cargo clippy --all --tests --benches -- -D warnings
# If this fails, run "cargo check" to update Cargo.lock,
# then add Cargo.lock to the PR.
- name: Check Cargo.lock doesn't need updating
Expand Down
3 changes: 3 additions & 0 deletions src/wasm-lib/kcl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ tower-lsp = { version = "0.20.0", features = ["proposed"] }
[features]
default = ["cli", "engine"]
cli = ["dep:clap"]
# For the lsp server, when run with stdout for rpc we want to disable println.
# This is used for editor extensions that use the lsp server.
disable-println = []
engine = []
pyo3 = ["dep:pyo3"]

Expand Down
4 changes: 0 additions & 4 deletions src/wasm-lib/kcl/src/engine/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,7 @@ impl EngineConnection {
loop {
match tcp_read.read().await {
Ok(ws_resp) => {
for e in ws_resp.errors.iter().flatten() {
println!("got error message: {} {}", e.error_code, e.message);
}
// If we got a batch response, add all the inner responses.
println!("got response: {:?}", ws_resp);
if let Some(kittycad::types::OkWebSocketResponseData::ModelingBatch { responses }) =
&ws_resp.resp
{
Expand Down
7 changes: 7 additions & 0 deletions src/wasm-lib/kcl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
//! the standard library implementation, a LSP implementation, generator for the docs, and more.
#![recursion_limit = "1024"]

macro_rules! println {
($($rest:tt)*) => {
#[cfg(not(feature = "disable-println"))]
std::println!($($rest)*)
}
}

pub mod ast;
pub mod coredump;
pub mod docs;
Expand Down
5 changes: 4 additions & 1 deletion src/wasm-lib/kcl/src/parser/parser_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2907,7 +2907,10 @@ let myBox = box([0,0], -3, -16, -10)
let tokens = crate::token::lexer(some_program_string).unwrap();
let parser = crate::parser::Parser::new(tokens);
let err = parser.ast().unwrap_err();
println!("{err}")
assert_eq!(
err.to_string(),
r#"syntax: KclErrorDetails { source_ranges: [SourceRange([30, 36])], message: "All expressions in a pipeline must use the % (substitution operator)" }"#
);
}
}

Expand Down
Loading