Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 15, 2025

This PR adds a new VSCode command Roughly: Show Syntax Tree that displays the Abstract Syntax Tree (AST) of the currently active R file.

Implementation Details

  • Command: roughly.showSyntaxTree - opens AST output in a virtual document beside the current editor
  • Execution: Uses the existing CLI command roughly debug ast <file> via child process
  • Display: Creates a virtual document provider that shows the formatted AST output
  • Error Handling: Proper validation for R files, saved files, and command execution failures

Usage

  1. Open an R file in VSCode
  2. Use Command Palette (Ctrl+Shift+P / Cmd+Shift+P)
  3. Type "Roughly: Show Syntax Tree"
  4. AST opens in new editor tab beside current file

Example

For R code:

library(dplyr)
data <- data.frame(x = 1:3, y = 4:6)
result <- data %>% filter(x > 1)

The command shows detailed AST structure including:

  • Program structure and comments
  • Function calls and library imports
  • Variable assignments and operators
  • Pipeline operations and function arguments
  • Data structure definitions

Technical Implementation

  • Reuses existing binary resolution logic from server commands
  • Follows functional programming style as requested
  • Minimal changes with focused functionality
  • Proper TypeScript typing and error handling
  • Added ESLint configuration for code quality
  • Virtual document provider for read-only AST display

Testing

  • Manually tested with various R code examples (functions, data manipulation, ggplot2)
  • Verified extension compiles without errors
  • Tested error scenarios (non-R files, unsaved files, binary failures)
  • Confirmed AST output matches CLI roughly debug ast functionality

Fixes #54.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits July 15, 2025 23:57
Copilot AI changed the title [WIP] Add new vscode command to show ast Add new VSCode command to show syntax tree Jul 16, 2025
Copilot finished work on behalf of felix-andreas-copilot July 16, 2025 00:11
@felix-andreas felix-andreas force-pushed the main branch 2 times, most recently from b04cd93 to adeb2a3 Compare July 18, 2025 22:53
@felix-andreas felix-andreas force-pushed the main branch 3 times, most recently from 4b7acf8 to f74a5a2 Compare September 19, 2025 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add new vscode command to show ast

2 participants