julia-vscode icon indicating copy to clipboard operation
julia-vscode copied to clipboard

Codelens Support in `julia` Files

Open huangyxi opened this issue 1 year ago • 3 comments

This PR attempts to support CodeLens for julia files (#858), enabling users to explore and execute code cells directly in the editor.

image

The initial commit only demonstrates the availability of CodeLens for julia files. To implement the complete functionality, there are two more tasks to be done.

  1. Currently, the julia.executeCell command is used to execute code cells. However, the range of the code cell is reliant on the pointer position, where the trigger of CodeLens actions may not enclose the current pointer position. https://github.com/julia-vscode/julia-vscode/blob/9b009459727161f9292d2890d6c5433ec6932960/src/interactive/repl.ts#L856-L857

To address this issue, I propose two separate approaches:

  • Workaround: Modify the julia.executeCell command to execute either the code cell enclosing the pointer position or the code cell enclosing the CodeLens trigger position.
  • General solution: Strip and refactor all source code related to code cell execution to a more general approach used in the vscode-R extension (https://github.com/REditorSupport/vscode-R/blob/master/src/rmarkdown/chunks.ts). The new approach will statically analyze delimiters of all code cells and then dynamically locate the active code cell based on the executed CodeLens or pointer position. Though this approach may require more computation resources, it may provide a more robust and flexible solution for code cell execution.

I would like to hear the community's opinion on this issue. Either way, I'm willing to implement the solution.

  1. To introduce a new command julia.executeAboveCells to execute all code cells above the current pointer position if the second solution above is adopted, which is also a common feature in Jupyter notebooks and vscode-R extension.
  • [ ] End-user documentation check. If this PR requires end-user documentation, please add that at https://github.com/julia-vscode/docs.

huangyxi avatar Apr 15 '24 17:04 huangyxi

I didn't look at the linked implementation in detail, but that second approach seems preferable.

pfitzseb avatar Apr 15 '24 20:04 pfitzseb