#Current NEOVIM config

18 messages · Page 1 of 1 (latest)

weak prawn
#

Let's use this post to share neovim setups for mojo!

#

2024-12-30

~/.congif/nvim/lua/plugins/mojo-conf.lua

return {
  "neovim/nvim-lspconfig",
  opts = {
    servers = {
      mojo = {
        -- this is required if you use magic-cli instead of modular-cli
        on_new_config = function()
          local result = vim.fn.system("magic shell")
          if vim.v.shell_error ~= 0 then
            vim.notify("error running `magic shell`: " .. result, vim.log.levels.error)
          end
        end,
      },
    },
  },
}

I'm using LazyVim with neovim 0.10 (it works on MacOS, but not on Linux)

digital cargo
#

i see

last canyon
#

This is my tree-sitter config for Mojo, using Lazy:

    "nvim-treesitter/nvim-treesitter",
    event = { "BufReadPost", "BufNewFile" },
    cmd = { "TSInstall", "TSBufEnable", "TSBufDisable", "TSModuleInfo" },
    build = ":TSUpdate",
    dependencies = {
      "nvim-treesitter/nvim-treesitter-textobjects",
    },
    opts = function()
      return require "plugins.configs.treesitter"
    end,
    config = function(_, opts)
      dofile(vim.g.base46_cache .. "syntax")
      require("nvim-treesitter.configs").setup(opts)
      -- use the python highlighter for .mojo files, which are recognized as conf ones
      -- vim.treesitter.language.register('python', 'conf')

      local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
      parser_config.mojo = {
        install_info = {
          url = "https://github.com/lsh/tree-sitter-mojo", -- local path or git repo
          files = {"src/parser.c"}, -- note that some parsers also require src/scanner.c or src/scanner.cc
          -- optional entries:
          branch = "main", -- default branch in case of git repo if different from master
          generate_requires_npm = false, -- if stand-alone parser without npm dependencies
          requires_generate_from_grammar = false, -- if folder contains pre-generated src/parser.c
        },
        filetype = "mojo", -- if filetype does not match the parser name
      }

      -- Set the comment string for Mojo files
      vim.api.nvim_create_autocmd("FileType", {
        pattern = "mojo",
        callback = function()
          vim.bo.commentstring = "# %s"
        end,
      })
    end,
  },
#

Installed with :TSInstall mojo

weak prawn
#

2025-01-03
~/.congif/nvim/lua/plugins/mojo-conf.lua

return {
  "neovim/nvim-lspconfig",
  opts = {
    servers = {
      mojo = {
        on_new_config = function(config)
          if vim.fn.executable("mojo-lsp-server") == 0 then
            -- try to run `magic shell`
            local result = vim.fn.system("magic shell")
            if vim.v.shell_error ~= 0 then
              vim.notify("LSP: " .. result, vim.log.levels.ERROR)
              vim.notify("(Run `magic shell` before entering neovim)", vim.log.levels.INFO)
              -- avoid trying to run mojo-lsp-server
              config.cmd = { "echo", "" }
              return
            end
          end
        end,
      },
    },
  },
}

I have not yet managed to get magic shell to run automatically on linux. But with this configuration at least a solution is offered through a notification.

light knoll
#

With Astronvim, I only have to configure this in astrolsp.lua - ```lua
servers = {
"mojo",
},

weak prawn
#
return {
  "neovim/nvim-lspconfig",
  opts = {
    servers = {
      mojo = {}
    }
  }
}

also worked with lazyvim before I removed the .modular folder to use magic only.

@light knoll could you share your installation details?

light knoll
weak prawn
#

hmm I didn't get this working

weak prawn
weak prawn
#

oh oh... I'm testing on macos, and it doesn't work either... some how I get mojo-lsp-server installed inside ~/.modular/pkg/...

weak prawn
#

This is the best I can do 😦

weak prawn
#

2025-01-03

-- ~/.congif/nvim/lua/plugins/mojo-conf.lua

return {
  "neovim/nvim-lspconfig",
  opts = {
    servers = {
      mojo = {
        on_new_config = function(config)
          if vim.fn.executable("mojo-lsp-server") == 0 then
            vim.notify(
              "(Run `magic shell` before entering neovim)",
              vim.log.levels.WARN,
              { title = "MOJO LSP NOT STARTED", icon = "🚨", timeout = 10000 }
            )
            -- avoid trying to run mojo-lsp-server
            config.cmd = { "echo", "" }
            return
          end
        end,
      },
    },
  },
}

After some iterations, I realized it was impossible to run magic shell once nvim started (neither on macOS nor Linux).
So this config requires you to run magic shell before starting nvim If so, it will run the LSP

jovial nexus
#

Where are you all getting your language server? I can't find it anywhere on the Modular website or in the magic --help menu. Is it bundled into "magic shell" somehow?

#

Oh, nevermind

#

figured it out