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

Include document specific debug info #16215

Merged
merged 3 commits into from
Feb 18, 2025
Merged

Conversation

dhruvmanila
Copy link
Member

@dhruvmanila dhruvmanila commented Feb 17, 2025

Summary

Related astral-sh/ruff-vscode#692.

Test Plan

When there's no active text document:

[Info  - 10:57:03 PM] Global:
executable = /Users/dhruv/work/astral/ruff/target/debug/ruff
version = 0.9.6
position_encoding = UTF16
workspace_root_folders = [
    "/Users/dhruv/playground/ruff",
]
indexed_configuration_files = [
    "/Users/dhruv/playground/ruff/pyproject.toml",
    "/Users/dhruv/playground/ruff/formatter/ruff.toml",
]
open_documents = 0
client_capabilities = ResolvedClientCapabilities {
    code_action_deferred_edit_resolution: true,
    apply_edit: true,
    document_changes: true,
    workspace_refresh: true,
    pull_diagnostics: true,
}

global_client_settings = ResolvedClientSettings {
    fix_all: true,
    organize_imports: true,
    lint_enable: true,
    disable_rule_comment_enable: true,
    fix_violation_enable: true,
    show_syntax_errors: true,
    editor_settings: ResolvedEditorSettings {
        configuration: None,
        lint_preview: None,
        format_preview: None,
        select: None,
        extend_select: None,
        ignore: None,
        exclude: None,
        line_length: None,
        configuration_preference: EditorFirst,
    },
}

When there's an active text document that's been passed as param:

[Info  - 10:53:33 PM] Global:
executable = /Users/dhruv/work/astral/ruff/target/debug/ruff
version = 0.9.6
position_encoding = UTF16
workspace_root_folders = [
    "/Users/dhruv/playground/ruff",
]
indexed_configuration_files = [
    "/Users/dhruv/playground/ruff/pyproject.toml",
    "/Users/dhruv/playground/ruff/formatter/ruff.toml",
]
open_documents = 1
client_capabilities = ResolvedClientCapabilities {
    code_action_deferred_edit_resolution: true,
    apply_edit: true,
    document_changes: true,
    workspace_refresh: true,
    pull_diagnostics: true,
}

Document:
uri = file:///Users/dhruv/playground/ruff/lsp/play.py
kind = Text
version = 1
client_settings = ResolvedClientSettings {
    fix_all: true,
    organize_imports: true,
    lint_enable: true,
    disable_rule_comment_enable: true,
    fix_violation_enable: true,
    show_syntax_errors: true,
    editor_settings: ResolvedEditorSettings {
        configuration: None,
        lint_preview: None,
        format_preview: None,
        select: None,
        extend_select: None,
        ignore: None,
        exclude: None,
        line_length: None,
        configuration_preference: EditorFirst,
    },
}
config_path = Some("/Users/dhruv/playground/ruff/pyproject.toml")

...

Replace ... at the end with the output of ruff check --show-settings path.py

@dhruvmanila dhruvmanila added the server Related to the LSP server label Feb 17, 2025
@dhruvmanila dhruvmanila force-pushed the dhruv/print-debug-info-return-string branch 2 times, most recently from c700a50 to 8abfba3 Compare February 17, 2025 17:18
@dhruvmanila dhruvmanila force-pushed the dhruv/debug-info-command branch 2 times, most recently from cd69876 to 3346e4f Compare February 17, 2025 17:28
Copy link
Contributor

github-actions bot commented Feb 17, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@dhruvmanila dhruvmanila force-pushed the dhruv/debug-info-command branch from 3346e4f to 62ff785 Compare February 18, 2025 04:40
Comment on lines 43 to 48
let argument: DebugCommandArgument = params.arguments.into_iter().next().map_or_else(
|| Ok(DebugCommandArgument::default()),
|value| serde_json::from_value(value).with_failure_code(ErrorCode::InvalidParams),
)?;
let output = debug_information(session, argument.uri)
.with_failure_code(ErrorCode::InternalError)?;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, we only look at the first argument but a potential new VS Code command could be to look at all opened documents which would require passing multiple arguments. But, I'm going to leave this for now.

@dhruvmanila dhruvmanila marked this pull request as ready for review February 18, 2025 04:42
Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great and i also forgot about it. At least, it never came to my mind when asking users for debugging information which is a shame.

@dhruvmanila dhruvmanila force-pushed the dhruv/debug-info-command branch from 75792db to 8408d65 Compare February 18, 2025 09:24
Base automatically changed from dhruv/print-debug-info-return-string to main February 18, 2025 09:46
@dhruvmanila dhruvmanila force-pushed the dhruv/debug-info-command branch from 8408d65 to 01dff16 Compare February 18, 2025 09:47
@dhruvmanila dhruvmanila merged commit ed9c18d into main Feb 18, 2025
20 checks passed
@dhruvmanila dhruvmanila deleted the dhruv/debug-info-command branch February 18, 2025 10:08
dhruvmanila added a commit to astral-sh/ruff-vscode that referenced this pull request Feb 18, 2025
## Summary

Related to astral-sh/ruff#16215

## Test Plan

The output in astral-sh/ruff#16215 is by using
this PR.
dcreager added a commit that referenced this pull request Feb 18, 2025
* main: (60 commits)
  [`refurb`] Manual timezone monkeypatching (`FURB162`) (#16113)
  [`pyupgrade`] Do not upgrade functional TypedDicts with private field names to the class-based syntax (`UP013`) (#16219)
  Improve docs for PYI019 (#16229)
  Refactor `CallOutcome` to `Result` (#16161)
  Fix minor punctuation errors (#16228)
  Include document specific debug info (#16215)
  Update server to return the debug info as string (#16214)
  [`airflow`] Group `ImportPathMoved` and `ProviderName` to avoid misusing (`AIR303`) (#16157)
  Fix unstable formatting of trailing end-of-line comments of parenthesized attribute values (#16187)
  Ignore source code actions for a notebook cell (#16154)
  Add FAQ entry for `source.*` code actions in Notebook (#16212)
  red-knot: move symbol lookups in `symbol.rs` (#16152)
  better error messages while loading configuration `extend`s (#15658)
  Format `index.css` (#16207)
  Improve API exposed on `ExprStringLiteral` nodes (#16192)
  Update Rust crate tempfile to v3.17.0 (#16202)
  Update cloudflare/wrangler-action action to v3.14.0 (#16203)
  Update NPM Development dependencies (#16199)
  Update Rust crate smallvec to v1.14.0 (#16201)
  Update Rust crate codspeed-criterion-compat to v2.8.0 (#16200)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
server Related to the LSP server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants