irongit

A Neovim plugin enabling you to solve LeetCode problems.

229 commits
Clone โ–พ
HTTPS
SSH
CLI
README.md

๐Ÿšจ leetcode.nvim is currently in the alpha stage of development ๐Ÿšจ


leetcode.nvim

๐Ÿ”ฅ Solve LeetCode problems within Neovim ๐Ÿ”ฅ

https://github.com/kawre/leetcode.nvim/assets/69250723/309088c9-4ff7-4dff-ab61-ab3f09b43740

โœจ Features

  • ๐Ÿ“Œ an intuitive dashboard for effortless navigation within leetcode.nvim

  • ๐Ÿ˜ question description formatting for a better readability

  • ๐Ÿ“ˆ LeetCode profile statistics within Neovim

  • ๐Ÿ”€ support for daily and random questions

  • ๐Ÿ’พ caching for optimized performance

๐Ÿ“ฌ Requirements

๐Ÿ“ฆ Installation

{
    "kawre/leetcode.nvim",
    build = ":TSUpdate html",
    dependencies = {
        "nvim-telescope/telescope.nvim",
        "nvim-lua/plenary.nvim", -- required by telescope
        "MunifTanjim/nui.nvim",

        -- optional
        "nvim-treesitter/nvim-treesitter",
        "rcarriga/nvim-notify",
        "nvim-tree/nvim-web-devicons",
    },
    opts = {
        -- configuration goes here
    },
}

๐Ÿ› ๏ธ Configuration

To see full configuration types see template.lua

โš™๏ธ default configuration

{
    ---@type string
    arg = "leetcode.nvim",

    ---@type lc.lang
    lang = "cpp",

    cn = { -- leetcode.cn
        enabled = false, ---@type boolean
        translate_problems = true, ---@type boolean
    },

    ---@type string
    directory = vim.fn.stdpath("data") .. "/leetcode/",

    ---@type boolean
    logging = true,

    cache = {
        update_interval = 60 * 60 * 24 * 7, ---@type integer 7 days
    },

    console = {
        open_on_runcode = true, ---@type boolean

        dir = "row", ---@type "col" | "row"

        size = {
            width = "90%", ---@type string | integer
            height = "75%", ---@type string | integer
        },

        result = {
            size = "60%", ---@type string | integer
        },

        testcase = {
            virt_text = true, ---@type boolean

            size = "40%", ---@type string | integer
        },
    },

    description = {
        position = "left", ---@type "top" | "right" | "bottom" | "left"

        width = "40%", ---@type string | integer
    },

    hooks = {
        ---@type fun()[]
        LeetEnter = {},

        ---@type fun(question: { lang: string })[]
        LeetQuestionNew = {},
    },

    ---@type boolean
    image_support = false, -- setting this to `true` will disable question description wrap
}

arg

Argument for Neovim

---@type string
arg = "leetcode.nvim"

See usage for more info

lang

Language to start your session with

---@type lc.lang
lang = "cpp"

cn

Use leetcode.cn instead of leetcode.com

cn = { -- leetcode.cn
    enabled = false, ---@type boolean
    translate_problems = true, ---@type boolean
},

directory

Where to store leetcode.nvim data

---@type string
directory = vim.fn.stdpath("data") .. "/leetcode/"

logging

Whether to log leetcode.nvim status notifications

---@type boolean
logging = true

hooks

List of functions that get executed on specified event

hooks = {
    ---@type fun()[]
    LeetEnter = {},

    ---@type fun(question: { lang: string })[]
    LeetQuestionNew = {},
},

image support

Whether to render question description images using image.nvim

---@type boolean
image_support = false, -- setting this to `true` will disable question description wrap

๐Ÿ“‹ Commands

Leet opens menu dashboard

  • menu same as Leet

  • console opens console pop-up for currently opened question

  • info opens a pop-up containing information about the currently opened question

  • tabs opens a picker with all currently opened question tabs

  • lang opens a picker to change the language of the current question

  • run run currently opened question

  • test same as Leet run

  • submit submit currently opened question

  • random opens a random question

  • daily opens the question of today

  • list opens a problemlist picker

  • desc toggle question description

    • toggle same as Leet desc
  • cookie

    • update opens a prompt to enter a new cookie

    • delete sign-out

  • cache

    • update updates cache

Leet list

Can take optional arguments. To stack argument values separate them by a ,

Leet list status=<status> difficulty=<difficulty>

๐Ÿš€ Usage

This plugin is meant to be used within a fresh Neovim instance. Meaning that to launch leetcode.nvim you have to pass arg as the first and only Neovim argument

nvim leetcode.nvim

Pop-ups

๐Ÿšจ Do not close leetcode.nvim pop-ups with :q ๐Ÿšจ

There are two shortcuts specifically designed for closing them which are q and Esc.

Sign In

It is required to be signed-in to use leetcode.nvim

https://github.com/kawre/leetcode.nvim/assets/69250723/b7be8b95-5e2c-4153-8845-4ad3abeda5c3

๐Ÿด Recipes

lazy loading

local leet_arg = "leetcode.nvim"

return {
    "kawre/leetcode.nvim",
    ...
    lazy = leet_arg ~= vim.fn.argv()[1],
    opts = {
        arg = leet_arg,
    },
    ...
}

โœ… Todo

  • [ ] CN version
  • [x] Statistics menu page
  • [ ] Docs
  • [x] Hints pop-up

๐Ÿ™Œ Credits