benlubas / molten-nvim

A neovim plugin for interactively running code with the jupyter kernel. Fork of magma-nvim with improvements in image rendering, performance, and more
GNU General Public License v3.0
551 stars 30 forks source link

[Help] [Quarto] code runner isn't initialised for the buffer #148

Closed pbower closed 7 months ago

pbower commented 8 months ago

Hi there,

I'm super excited about this plugin, so much so that I've spent a solid amount of time getting things ready.

I'd really appreciate it if someone is happy to take a quick look and see where things are going wrong. I'm keen to execute my notebook cells with Quarto, except it's missing the 'runner'. image image

Also, for some reason I don't get the lovely cells from the video that say `Python , and instead it's a '# +' affair. image

It would be a massive help if someone can help clarify these 2 things.

Please see details below. You're a legend!

what you're trying to do_

what you've tried (if anything)_

questions you'd like answered

  1. How to run/initialise Quarto to enable running the notebook cells.
  2. Would it be possible to confirm if QuartoActivate is what needs to be run each time, before executing cells? What other steps are needed? Any idea if the bug above is likely version related
Checkhealth output:

jupytext: require("jupytext.health").check()

jupytext.nvim ~
- OK Jupytext is available

==============================================================================
mkdp: health#mkdp#check

- Platform: linux
- Nvim Version: NVIM v0.9.5
  Build type: Release
  LuaJIT 2.1.1692716794

  system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/__w/neovim/neovim/build/nvim.AppDir/usr/share/nvim"

  Run :checkhealth for more info
- Node version: v18.19.0
- Script: /home/pbower/.local/share/nim/plugged/markdown-preview.nvim/app/server.js
- Script exists: 1
- OK Using node

==============================================================================
molten: require("molten.health").check()

molten-nvim ~
- OK NeoVim >=0.9
- OK Python >=3.10
- OK Python module pynvim found
- OK Python module jupyter-client found
- OK Python module cairosvg found
- OK Python module pnglatex found
- OK Python module plotly found
- OK Python module kaleido found
- OK Python module pyperclip found
- OK Python module nbformat found

==============================================================================
nvim: require("nvim.health").check()

Configuration ~
- OK no issues found

Runtime ~
- OK $VIMRUNTIME: /home/pbower/.local/nvim/share/nvim/runtime

Performance ~
- OK Build type: Release

Remote Plugins ~
- OK Up to date

terminal ~
- key_backspace (kbs) terminfo entry: `key_backspace=\177`
- key_dc (kdch1) terminfo entry: `key_dc=\E[3~`
- $COLORTERM="truecolor"

==============================================================================
nvim-treesitter: require("nvim-treesitter.health").check()

Installation ~
- WARNING `tree-sitter` executable not found (parser generator, only needed for :TSInstallFromGrammar, not required for :TSInstall)
- OK `node` found v18.19.0 (only needed for :TSInstallFromGrammar)
- OK `git` executable found.
- OK `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
  Version: cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
- OK Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.

OS Info:
{
  machine = "x86_64",
  release = "6.5.0-17-generic",
  sysname = "Linux",
  version = "#17~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 16 14:32:32 UTC 2"
} ~

Parser/Features         H L F I J
  - c                   ✓ ✓ ✓ ✓ ✓
  - javascript          ✓ ✓ ✓ ✓ ✓
  - lua                 ✓ ✓ ✓ ✓ ✓
  - python              ✓ ✓ ✓ ✓ ✓
  - query               ✓ ✓ ✓ ✓ ✓
  - r                   ✓ ✓ . ✓ ✓
  - rust                ✓ ✓ ✓ ✓ ✓
  - vim                 ✓ ✓ ✓ . ✓
  - vimdoc              ✓ . . . ✓

  Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
         +) multiple parsers found, only one will be used
         x) errors found in the query, try to run :TSUpdate {lang} ~

==============================================================================
provider: health#provider#check

Clipboard (optional) ~
- OK Clipboard tool found: xclip

Python 3 provider (optional) ~
- Using: g:python3_host_prog = "/home/pbower/.venvs/nvim/bin/python3"
- Executable: /home/pbower/.venvs/nvim/bin/python3
- Python version: 3.10.12
- pynvim version: 0.5.0
- OK Latest pynvim is installed.

Python virtualenv ~
- $VIRTUAL_ENV is set to: /home/pbower/dev/sc/<myproject>/.venv
- Python version: 3.10.12
- OK $VIRTUAL_ENV provides :!python.

===== Installed extensions ===== ~

==============================================================================
vim.treesitter: require("vim.treesitter.health").check()

- Nvim runtime ABI version: 14
- OK Parser: javascript ABI: 14, path: /home/pbower/.local/share/nim/plugged/nvim-treesitter/parser/javascript.so
- OK Parser: lua        ABI: 14, path: /home/pbower/.local/share/nim/plugged/nvim-treesitter/parser/lua.so
- OK Parser: python     ABI: 14, path: /home/pbower/.local/share/nim/plugged/nvim-treesitter/parser/python.so
- OK Parser: r          ABI: 14, path: /home/pbower/.local/share/nim/plugged/nvim-treesitter/parser/r.so
- OK Parser: rust       ABI: 14, path: /home/pbower/.local/share/nim/plugged/nvim-treesitter/parser/rust.so
- OK Parser: vim        ABI: 14, path: /home/pbower/.local/share/nim/plugged/nvim-treesitter/parser/vim.so
- OK Parser: vimdoc     ABI: 14, path: /home/pbower/.local/share/nim/plugged/nvim-treesitter/parser/vimdoc.so
- OK Parser: c          ABI: 14, path: /home/pbower/.local/nvim/lib/nvim/parser/c.so
- OK Parser: lua        ABI: 14, path: /home/pbower/.local/nvim/lib/nvim/parser/lua.so
- OK Parser: query      ABI: 14, path: /home/pbower/.local/nvim/lib/nvim/parser/query.so
- OK Parser: vim        ABI: 14, path: /home/pbower/.local/nvim/lib/nvim/parser/vim.so
- OK Parser: vimdoc     ABI: 14, path: /home/pbower/.local/nvim/lib/nvim/parser/vimdoc.so

NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1692716794

Plugs include:
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'hrsh7th/nvim-cmp' 
Plug 'hrsh7th/cmp-nvim-lsp' 
Plug 'hrsh7th/cmp-buffer' 
Plug 'hrsh7th/cmp-path' "
Plug 'hrsh7th/cmp-cmdline' 
Plug '3rd/image.nvim'
Plug 'GCBallesteros/jupytext.nvim'
Plug 'benlubas/molten-nvim'
Plug 'quarto-dev/quarto-nvim'
Plug 'jmbuhr/otter.nvim'
Plug 'neovim/nvim-lspconfig'

Kitty is v0.32.2

init.vim:

...
" Image.Nvim (default) config

lua << EOF
package.path = package.path .. ";" .. vim.fn.expand("$HOME") .. "/.luarocks/share/lua/5.1/?/init.lua;"
package.path = package.path .. ";" .. vim.fn.expand("$HOME") .. "/.luarocks/share/lua/5.1/?.lua;"
EOF

lua << EOF
require("image").setup({
  backend = "kitty",
  integrations = {
    markdown = {
      enabled = true,
      clear_in_insert_mode = false,
      download_remote_images = true,
      only_render_image_at_cursor = false,
      filetypes = { "markdown", "vimwiki" }, -- markdown extensions (ie. quarto) can go here
    },
    neorg = {
      enabled = true,
      clear_in_insert_mode = false,
      download_remote_images = true,
      only_render_image_at_cursor = false,
      filetypes = { "norg" },
    },
  },
  max_width = nil,
  max_height = nil,
  max_width_window_percentage = nil,
  max_height_window_percentage = 50,
  window_overlap_clear_enabled = false, -- toggles images when windows are overlapped
  window_overlap_clear_ft_ignore = { "cmp_menu", "cmp_docs", "" },
  editor_only_render_when_focused = false, -- auto show/hide images when the editor gains/looses focus
  tmux_show_only_in_active_window = false, -- auto show/hide images in the correct Tmux window (needs visual-activity off)
  hijack_file_patterns = { "*.png", "*.jpg", "*.jpeg", "*.gif", "*.webp" }, -- render image files as images when opened
})
EOF

let g:python3_host_prog = expand("~/.venvs/nvim/bin/python3")

lua << EOF
vim.g.molten_auto_open_output = true
vim.g.molten_image_provider = 'image.nvim'
vim.g.molten_wrap_output = true 
vim.g.molten_virt_text_output = true
vim.g.molten_virt_lines_off_by_1 = true
vim.g.molten_auto_open_html_in_browser = true
vim.g.molten_output_crop_border = true
vim.g.molten_output_show_more = true
vim.g.molten_output_virt_lines = true
vim.g.molten_output_win_cover_gutter = false
vim.g.molten_tick_rate = 500
vim.g.molten_use_border_highlights = true
EOF

nnoremap <silent><A-i> <cmd>MoltenInit<cr>
nnoremap <silent><A-p> <cmd>MoltenInfo<cr>

function! GoToCodeCell()
    " Prompt the user to enter the cell number
    let l:cellNumber = input('Enter code cell number: ')
    " Execute the MoltenGoto command with the entered number
    execute 'MoltenGoto ' . l:cellNumber
endfunction

nnoremap <silent><A-1> <cmd>MoltenGoto 1<CR>
nnoremap <silent><A-t> :call GoToCodeCell()<CR>
nnoremap <silent><A-]> <cmd>MoltenNext<CR>
nnoremap <silent><A-[> <cmd>MoltenPrev<CR>
nnoremap <silent><A-l> <cmd>MoltenEvaluateLine<CR>
nnoremap <silent><A-v> <cmd>MoltenEvaluateVisual<CR>gv
nnoremap <silent><A-o> <cmd>MoltenEvaluateOperator<CR>
nnoremap <silent><A-r> <cmd>MoltenReevaluateCell<CR>
nnoremap <silent><A-q> <cmd>MoltenDelete<CR>
nnoremap <silent><A-k> <cmd>MoltenShowOutput<CR>
nnoremap <silent><A-j> <cmd>MoltenHideOutput<CR>
nnoremap <silent><A-cr> <cmd>:noautocmd MoltenEnterOutput<CR>
nnoremap <silent><A-0> <cmd>MoltenInterrupt<CR>
nnoremap <silent><A-)> <cmd>MoltenRestart<CR>
nnoremap <silent><A-w> <cmd>MoltenOpenInBrowser<CR>
nnoremap <silent><A-!> <cmd>MoltenExportOutput<CR>
nnoremap <silent><A-@> <cmd>MoltenImportOutput<CR>
nnoremap <silent><A-#> <cmd>MoltenSave<CR>
nnoremap <silent><A-$> <cmd>MoltenLoad<CR>

lua << EOF
require('quarto').setup({
  debug = false,
  closePreviewOnExit = true,
  lspFeatures = {
    enabled = true,
    languages = { 'python', 'javascript', 'rust', 'bash', 'r' },
    chunks = 'curly', -- 'curly' or 'all'
    diagnostics = {
      enabled = true,
      triggers = { "BufWritePost" }
    },
    completion = {
      enabled = true,
    },
  },
  codeRunner = {
    enabled = true,
    default_method = "molten", -- 'molten' or 'slime'
    ft_runners = { python = "molten" }, -- filetype to runner, ie. `{ python = "molten" }`.
                     -- Takes precedence over `default_method`
    never_run = { "yaml" }, -- filetypes which are never sent to a code runner
  },
  keymap = {
    hover = 'K',
    definition = 'gd',
    rename = '<leader>lR',
    references = 'gr',
    format = '<leader>gf'
  }
})
EOF

lua << EOF
require("quarto").activate()
EOF

lua << EOF
local runner = require("quarto.runner")
vim.keymap.set("n", "<localleader>rc", runner.run_cell,  { desc = "run cell", silent = true })
vim.keymap.set("n", "<localleader>ra", runner.run_above, { desc = "run cell and above", silent = true })
vim.keymap.set("n", "<localleader>rA", runner.run_all,   { desc = "run all cells", silent = true })
vim.keymap.set("n", "<localleader>rl", runner.run_line,  { desc = "run line", silent = true })
vim.keymap.set("v", "<localleader>r",  runner.run_range, { desc = "run visual range", silent = true })
vim.keymap.set("n", "<localleader>RA", function()
  runner.run_all(true)
end, { desc = "run all cells of all languages", silent = true })
EOF

"lua << EOF
"vim.keymap.set('n', '<leader>qp', quarto.quartoPreview, { silent = true, noremap = true })
"EOF

" Per https://github.com/benlubas/molten-nvim/blob/main/docs/Notebook-Setup.md
lua << EOF
-- change the configuration when editing a python file
vim.api.nvim_create_autocmd("BufEnter", {
  pattern = "*.py",
  callback = function(e)
    if string.match(e.file, ".otter.") then
      return
    end
    if require("molten.status").initialized() == "Molten" then
      vim.fn.MoltenUpdateOption("virt_lines_off_by_1", false)
      vim.fn.MoltenUpdateOption("virt_text_output", false)
    else
      vim.g.molten_virt_lines_off_by_1 = false
      vim.g.molten_virt_text_output = false
    end
  end,
})

-- Undo those config changes when we go back to a markdown or quarto file
vim.api.nvim_create_autocmd("BufEnter", {
  pattern = { "*.qmd", "*.md", "*.ipynb" },
  callback = function(e)
    if string.match(e.file, ".otter.") then
      return
    end
    if require("molten.status").initialized() == "Molten" then
      vim.fn.MoltenUpdateOption("virt_lines_off_by_1", true)
      vim.fn.MoltenUpdateOption("virt_text_output", true)
    else
      vim.g.molten_virt_lines_off_by_1 = true
      vim.g.molten_virt_text_output = true
    end
  end,
})

require("jupytext").setup({ style = "light" })

-- disable Pyright diagnostic issue 
require("lspconfig")["pyright"].setup({
    on_attach = on_attach,
    capabilities = capabilities,
    settings = {
        python = {
            analysis = {
                diagnosticSeverityOverrides = {
                    reportUnusedExpression = "none",
                },
            },
        },
    },
})
EOF

Thanks so much!

benlubas commented 8 months ago

chunks = 'curly', -- 'curly' or 'all'

set this to 'all', curly will only pull stuff from quarto code cells.

If that doesn't fix the issue, make sure your treesitter parsers and nvim-treesitter are up to date.

benlubas commented 7 months ago

@pbower is this still an issue for you? or can I close this?