Code Monkey home page Code Monkey logo

Comments (9)

i3d avatar i3d commented on June 15, 2024 2

I also just wanted to say 'Huge Thanks' to MunifTanjim that this plugin is pretty much achieved all my wishes wanting for a flexible statusline (the LSP status also worked as well with the latest fix). I was using lualine and now I am fully switched. Thanks for the great work!

from nougat.nvim.

MunifTanjim avatar MunifTanjim commented on June 15, 2024 1

Now you can do:

local lsp_servers = nut.lsp.servers.create({
  ctx = {
    content = {
      lua_ls = "LuaLS",
    },
    hl = {
      lua_ls = { fg = "cyan" },
    },
  },
  hl = { bg = "gray", fg = "white" },
  sep_left = sep.left_lower_triangle_solid(true),
  config = {
    content = function(client, item)
      return {
        content = item.ctx.content[client.name] or client.name,
        hl = item.ctx.hl[client.name],
      }
    end,
    sep = " ",
  },
  suffix = " ",
})

You can format/highlight the display value however you want in the config.content function. This is the type for it:

---@field content? fun(client: lsp.Client, item: NougatItem, ctx: nougat_ctx):nil|string|string[]|{content:string,hl?:nougat_hl_def}|{content:string,hl?:nougat_hl_def}[]

If you return nil that server will not be rendered.

@uhooi @i3d

from nougat.nvim.

MunifTanjim avatar MunifTanjim commented on June 15, 2024 1

You need to require it first. So it'll be like this:

local nut = {
  lsp = {
    servers = require("nougat.nut.lsp.servers"),
  }
}

local lsp_servers = nut.lsp.servers.create({

Or just:

local lsp_servers = require("nougat.nut.lsp.servers").create({

from nougat.nvim.

uhooi avatar uhooi commented on June 15, 2024 1

Nice! Thanks. uhooi/dotfiles@53cc886

from nougat.nvim.

MunifTanjim avatar MunifTanjim commented on June 15, 2024

Can you give me a few examples? Which LSP information are you thinking about?

from nougat.nvim.

uhooi avatar uhooi commented on June 15, 2024

This setting displays the name and ID of the language server. How's that?

nougat.nvim config
https://github.com/uhooi/dotfiles/blob/12df54582f6a539fae0d30f6dcb88bf8c825a5fe/.config/nvim/lua/plugins/config/nouget.lua

local lsp_util = require('plugins.config.shared.lsp_util')

-- ...

-- lsp info {{{
local lsp_info = (function()
  local item = Item {
    sep_left = sep.left_half_circle_solid(true),
    content = {
      Item {
        hl = { bg = color.aqua, fg = color.bg },
        hidden = function(_, _)
          return lsp_util.names == ''
        end,
        content = lsp_util.names,
      },
    },
    sep_right = sep.right_half_circle_solid(true),
  }

  return item
end)()
-- }}}

-- tabline {{{
local tal = Bar('tabline')
tal:add_item(lsp_info)
bar_util.set_tabline(tal)
-- }}}

lsp_util.lua
https://github.com/uhooi/dotfiles/blob/12df54582f6a539fae0d30f6dcb88bf8c825a5fe/.config/nvim/lua/plugins/config/shared/lsp_util.lua

local M = {}

function M:names()
  local clients = vim
    .iter(vim.lsp.get_clients { bufnr = 0 })
    :map(function(client)
      if client.name == 'null-ls' then
        return ('null-ls[%s](' .. client.id .. ')'):format(table.concat(
          vim
            .iter(require('null-ls.sources').get_available(vim.bo.filetype))
            :map(function(source)
              return source.name
            end)
            :totable(),
          ', '
        ))
      else
        return client.name .. '(' .. client.id .. ')'
      end
    end)
    :totable()
  return '' .. ' ' .. table.concat(clients, ', ')
end

return M

right-upper
スクリーンショット 2023-11-21 11 52 08

from nougat.nvim.

i3d avatar i3d commented on June 15, 2024

This seems awesome. Do you have more thorough doc on how to integrate the above snippet into the configs (e.g. your example configs are thorough but I don't know how to integrate, sorry for the ignorance).

For now, I just copy&paste the snippet into one of the examples (slanty.lua) you have and I got this error

local lsp_servers = nut.lsp.servers.create({ <- attempt to index field 'lsp' (a nil value) 

from nougat.nvim.

i3d avatar i3d commented on June 15, 2024

I see. How to config other lsps other than lua_ls? Looks like you had that for example, but I have a few lsps I'd like to add as well. Thanks so much!!

from nougat.nvim.

MunifTanjim avatar MunifTanjim commented on June 15, 2024
local lsp_servers = nut.lsp.servers.create({
  -- whatever you set here, will be available as `item.ctx`
  -- doc: https://github.com/MunifTanjim/nougat.nvim/tree/main/lua/nougat/item#ctx
  ctx = {
    content = {
      lua_ls = "LuaLS",
    },
    hl = {
      lua_ls = { fg = "cyan" },
    },
  },
  hl = { bg = "gray", fg = "white" },
  sep_left = sep.left_lower_triangle_solid(true),
  config = {
    content = function(client, item)
      if client.name == "copilot" then
        -- if you return nothing, that lsp server will be hidden.
        -- so 'copilot' lsp will be hidden
        return
      end

      return {
        -- `item.ctx.content` has value for `lua_ls`, so it'll be displayed as `LuaLS`.
        -- Other LSP servers will be displayed as default `client.name`
        content = item.ctx.content[client.name] or client.name,
        -- `item.ctx.hl` has value for `lua_ls`, so it'll be displayed with `cyan` color.
        -- Other LSP servers will have default/no colors.
        hl = item.ctx.hl[client.name],
      }
    end,
    sep = " ",
  },
  suffix = " ",
})

As you see, it's very flexible. You can do whatever you want.

If you want to give custom name (e.g. LuaLS) for other LSP servers, you can add them in ctx.content table. If you want to change highlight for them, set that in ctx.hl.

You can also use ctx for hiding lsp servers too, for example:

local lsp_servers = nut.lsp.servers.create({
  ctx = {
    hidden = {
      copilot = true,
    },
  },
  config = {
    content = function(client, item)
      if item.ctx.hidden[item.name] then
        return
      end
      -- do other stuffs
    end,
  },
})

Hope that helps.

from nougat.nvim.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.