Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(API): add emmylua annotations #378

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Conversation

kylo252
Copy link

@kylo252 kylo252 commented Apr 9, 2022

I think it might be better to let the API documentation live inside the code, and it also benefits from LSP capabilities

image


TODO

  • I've only added a few so far
  • autocompletion seems busted, I have a feeling it's something to do with some internal cache invalidation

@L3MON4D3
Copy link
Owner

L3MON4D3 commented Apr 9, 2022

I agree, it makes sense to have the documentation next to the code, should prevent it becoming outdated.

It would be really cool to automatically generate the entries in DOC.md (because I'd like to keep those as well) from these annotations, do you know if there are ways to do that?

@kylo252
Copy link
Author

kylo252 commented Apr 9, 2022

I agree, it makes sense to have the documentation next to the code, should prevent it becoming outdated.

It would be really cool to automatically generate the entries in DOC.md (because I'd like to keep those as well) from these annotations, do you know if there are ways to do that?

I was looking earlier at ldoc which is able to generate html, and in theory markdown as well, but I could never get it to work with markdown. I think it's missing a template or something.

There's also this script from neovim-core, https://github.com/neovim/neovim/blob/8055f9857b8e384634d457533dfdb08618fc36f0/scripts/gen_vimdoc.py#L2

Lastly, I had an idea to leverage LSP for this, but it's a bit fiddley (redirect hover request output)

  local write_tmpfile = function(data)
    local tmpname = os.tmpname()
    local file = io.open(tmpname, "w")
    if type(data) == "table" then
      data = table.concat(data, "\n")
    end
    file:write(data)
    file:close()
    return tmpname
  end
  local util = require "vim.lsp.util"
  vim.lsp.handlers["textDocument/hover"] = function(_, result, ctx, config)
    config = config or {}
    config.focus_id = ctx.method
    if not (result and result.contents) then
      -- return { 'No information available' }
      return
    end
    local markdown_lines = util.convert_input_to_markdown_lines(result.contents)
    markdown_lines = util.trim_empty_lines(markdown_lines)
    if vim.tbl_isempty(markdown_lines) then
      -- return { 'No information available' }
      return
    end
    local tmpfile = write_tmpfile(markdown_lines) -- can also just copy the lines into some register instead
    print(tmpfile)
    vim.cmd([[edit ]] .. tmpfile)
    return tmpfile
  end

@L3MON4D3
Copy link
Owner

L3MON4D3 commented Apr 9, 2022

LDoc looks promising, but I'm surprised that there is no tool that straightforwardly generates markdown
The LSP approach is interesting, is there a way to automate it?

@kylo252
Copy link
Author

kylo252 commented Apr 11, 2022

is there a way to automate it?

Here's my script so far, just give it a valid bufnr (check :LspInfo)
https://gist.github.com/kylo252/7b3edb23b55197316a33916fd79d942f

Here are the results, which as you can see need better formatting, but that's why I included the raw response as well
https://gist.github.com/kylo252/1dcc3f9da60e42786d7088caa8441f67

I'm also counting on the fact that you have more experience with string manipulation 😃

@L3MON4D3
Copy link
Owner

Oh wow, that looks pretty good already 👍👍
I won't be able to really get into helping you with it for some time though :/

@saadparwaiz1
Copy link
Contributor

There's also this treesitter module available for generating documentation thorough Emmy

@L3MON4D3
Copy link
Owner

L3MON4D3 commented May 3, 2022

Interesting, but it only generates vimdoc (afaict) :/

@saadparwaiz1
Copy link
Contributor

seems like this does the job? spinx generates rst by default but that works on github. if markdown is required this extension can be used?

@hinell
Copy link

hinell commented Mar 29, 2023

Wonder why this one wasn't merged. Nice PR. Many projects are underdocumented.

@L3MON4D3
Copy link
Owner

L3MON4D3 commented Oct 4, 2023

Hey @kylo252, are you fine with merging this as-is (or, more-or-less as-is, after looking into how up to date it still is)?

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.

4 participants