Giter Club home page Giter Club logo

leetcode.nvim's Introduction

leetcode.nvim

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

๐Ÿ‡บ๐Ÿ‡ธ English, ๐Ÿ‡จ๐Ÿ‡ณ ็ฎ€ไฝ“ไธญๆ–‡

demo.mp4

Caution

This plugin has been primarily tested with Java. If you encounter any errors while using other languages, please open an issue to report them.

โœจ 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
        translator = true, ---@type boolean
        translate_problems = true, ---@type boolean
    },

    ---@type lc.storage
    storage = {
        home = vim.fn.stdpath("data") .. "/leetcode",
        cache = vim.fn.stdpath("cache") .. "/leetcode",
    },

    ---@type table<string, boolean>
    plugins = {
        non_standalone = false,
    },

    ---@type boolean
    logging = true,

    injector = {}, ---@type table<lc.lang, lc.inject>

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

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

        dir = "row", ---@type lc.direction

        size = { ---@type lc.size
            width = "90%",
            height = "75%",
        },

        result = {
            size = "60%", ---@type lc.size
        },

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

            size = "40%", ---@type lc.size
        },
    },

    description = {
        position = "left", ---@type lc.position

        width = "40%", ---@type lc.size

        show_stats = true, ---@type boolean
    },

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

        ---@type fun(question: lc.ui.Question)[]
        ["question_enter"] = {},

        ---@type fun()[]
        ["leave"] = {},
    },

    keys = {
        toggle = { "q" }, ---@type string|string[]
        confirm = { "<CR>" }, ---@type string|string[]

        reset_testcases = "r", ---@type string
        use_testcase = "U", ---@type string
        focus_testcases = "H", ---@type string
        focus_result = "L", ---@type string
    },

    ---@type lc.highlights
    theme = {},

    ---@type boolean
    image_support = false,
}

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"
available languages
Language lang
C++ cpp
Java java
Python python
Python3 python3
C c
C# csharp
JavaScript javascript
TypeScript typescript
PHP php
Swift swift
Kotlin kotlin
Dart dart
Go golang
Ruby ruby
Scala scala
Rust rust
Racket racket
Erlang erlang
Elixir elixir
Bash bash

cn

Use leetcode.cn instead of leetcode.com

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

storage

storage directories

---@type lc.storage
storage = {
    home = vim.fn.stdpath("data") .. "/leetcode",
    cache = vim.fn.stdpath("cache") .. "/leetcode",
},

plugins

plugins list

---@type table<string, boolean>
plugins = {
    non_standalone = false,
},

logging

Whether to log leetcode.nvim status notifications

---@type boolean
logging = true

injector

Inject code before or after your solution, injected code won't be submitted or run.

default imports

You can also pass before = true to inject default imports for the language. Supported languages are python, python3, java

Access default imports via require("leetcode.config.imports")

injector = { ---@type table<lc.lang, lc.inject>
    ["python3"] = {
        before = true
    },
    ["cpp"] = {
        before = { "#include <bits/stdc++.h>", "using namespace std;" },
        after = "int main() {}",
    },
    ["java"] = {
        before = "import java.util.*;",
    },
}

hooks

List of functions that get executed on specified event

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

    ---@type fun(question: lc.ui.Question)[]
    ["question_enter"] = {},

    ---@type fun()[]
    ["leave"] = {},
},

theme

Override the default theme.

Each value is the same type as val parameter in :help nvim_set_hl

---@type lc.highlights
theme = {
    ["alt"] = {
        bg = "#FFFFFF",
    },
    ["normal"] = {
        fg = "#EA4AAA",
    },
},

image support

Whether to render question description images using image.nvim

Warning

Enabling this will disable question description wrap, because of 3rd/image.nvim#62 (comment)

---@type boolean
image_support = false,

๐Ÿ“‹ Commands

Leet opens menu dashboard

  • menu same as Leet

  • exit close leetcode.nvim

  • 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

  • yank yanks the current question solution

  • 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 problem list picker

  • open opens the current question in a default browser

  • reset reset current question to default code definition

  • last_submit retrieve last submitted code for the current question

  • restore try to restore default question layout

  • inject re-inject code for the current question

  • session

    • create create a new session

    • change change the current session

    • update update the current session in case it went out of sync

  • desc toggle question description

    • toggle same as Leet desc

    • stats toggle description stats visibility

  • cookie

    • update opens a prompt to enter a new cookie

    • delete sign-out

  • cache

    • update updates cache

Some commands can take optional arguments. To stack argument values separate them by a ,

  • Leet list

    Leet list status=<status> difficulty=<difficulty>
    
  • Leet random

    Leet random status=<status> difficulty=<difficulty> tags=<tags>
    

๐Ÿš€ Usage

This plugin can be initiated in two ways:

  • To start leetcode.nvim, simply pass arg as the first and only Neovim argument

    nvim leetcode.nvim
    
  • (Experimental) Alternatively, you can use :Leet command to open leetcode.nvim within your preferred dashboard plugin. The only requirement is that Neovim must not have any listed buffers open.

Switching between questions

To switch between questions, use Leet tabs

Sign In

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

signin.mp4

๐Ÿด Recipes

๐Ÿ’ค lazy loading with lazy.nvim

Warning

opting for either option makes the alternative launch method unavailable due to lazy loading

  • with arg

    local leet_arg = "leetcode.nvim"
    {
        "kawre/leetcode.nvim",
        lazy = leet_arg ~= vim.fn.argv()[1],
        opts = { arg = leet_arg },
    }
  • with :Leet

    {
        "kawre/leetcode.nvim",
        cmd = "Leet",
    }

๐Ÿงฉ Plugins

Non-Standalone mode

To run leetcode.nvim in a non-standalone mode (i.e. not with argument or an empty Neovim session), enable the non_standalone plugin in your config:

plugins = {
    non_standalone = true,
}

You can then exit leetcode.nvim using :Leet exit command

๐Ÿ™Œ Credits

leetcode.nvim's People

Contributors

alowain avatar bacbia3696 avatar eric-song-nop avatar hakonharnes avatar herschel-ma avatar igorgue avatar kawre avatar mrcjkb avatar ofseed avatar sgarg26 avatar willothy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

leetcode.nvim's Issues

Plugin won't open after 2f9b199e5493c556569ecca5ad08c924706110ea

This is the last commit where I can use nvim leetcode.nvim.

Any other commit I've tried after that one, won't start leetcode.nvim

My config

  -- Last functional commit
  {
    "kawre/leetcode.nvim",
    commit = "2f9b199e5493c556569ecca5ad08c924706110ea",
    event = "VeryLazy",
    dependencies = {
      "nvim-treesitter/nvim-treesitter",
      "nvim-telescope/telescope.nvim",
      "nvim-lua/plenary.nvim",
      "MunifTanjim/nui.nvim",
      "nvim-tree/nvim-web-devicons",
      "rcarriga/nvim-notify",
    },
    opts = {
      lang = "typescript",
    },
    config = function(_, opts) require("leetcode").setup(opts) end,
  },

Screenshots

Working commit
screenshot_2023-10-22_03-06-16_573320584

After that
screenshot_2023-10-22_03-06-39_148783201

ๆ— ๆณ•ๆ‰“ๅผ€ๅ’Œไฝฟ็”จ่ฟ™ไธชๆ’ไปถ

็ณป็ปŸ๏ผšmacos
neovim๏ผš0.9.4

่ฟ™ๆ˜ฏๆˆ‘็š„้…็ฝฎ

local leet_arg = "leetcode.nvim"
return {
  "kawre/leetcode.nvim",
  build = ":TSUpdate html",
  dependencies = {
    "nvim-telescope/telescope.nvim",
    "nvim-lua/plenary.nvim",
    "MunifTanjim/nui.nvim",
    "nvim-treesitter/nvim-treesitter",
    "rcarriga/nvim-notify",
    "nvim-tree/nvim-web-devicons",
  },
  lazy = leet_arg ~= vim.fn.argv()[1],
  dev = true,
  opts = {
    arg = leet_arg,
    lang = "js",
    debug = true,
    image_support = false,
    cache = { update_interval = 60 * 60 },
    cn = {
      enabled = true,
    },
  },
  keys = {
    { "<leader>lq", mode = { "n" }, "<cmd>Leet tabs<cr>" },
    { "<leader>lm", mode = { "n" }, "<cmd>Leet menu<cr>" },
    { "<leader>lc", mode = { "n" }, "<cmd>Leet console<cr>" },
    { "<leader>lh", mode = { "n" }, "<cmd>Leet info<cr>" },
    { "<leader>ll", mode = { "n" }, "<cmd>Leet lang<cr>" },
    { "<leader>ld", mode = { "n" }, "<cmd>Leet desc<cr>" },
    { "<leader>lr", mode = { "n" }, "<cmd>Leet run<cr>" },
    { "<leader>ls", mode = { "n" }, "<cmd>Leet submit<cr>" },
  },
}
image

่ฟ™ไธชๆ’ไปถ่ขซๅฎ‰่ฃ…ๅœจ/projects/leetcode.nvim๏ผŒไฝ†ๆ˜ฏๅนถๆฒกๆœ‰่ฟ™ไธชๆ–‡ไปถๅคน

ไฝฟ็”จnvim leetcode.nvim่ฟ™ไธช่กŒๅ‘ฝไปคๆ—ถๆฒกๆœ‰start็•Œ้ข

2023-12-22_12-52-13.mp4

Unable to open plugin

Problem

I am unable to open the plugin. I've tried both nvim leetcode.nvim in the terminal, as well as :Leet in neovim.

What i've tried

I've thought it might be the barbar.nvim plugin that was giving me trouble, so i tried removing that.

Files

Packer file:

vim.cmd [[packadd packer.nvim]]

return require('packer').startup(function(use)
	-- Packer can manage itself
	use 'wbthomason/packer.nvim'
	use {
		'nvim-telescope/telescope.nvim', tag = '0.1.5',
        requires = {
            'duane9/nvim-rg',
            'nvim-lua/plenary.nvim'
        }
	}
    use {
        'nvim-telescope/telescope-file-browser.nvim', -- not working for some reason
        requires = {
            "nvim-telescope/telescope.nvim",
            "nvim-lua/plenary.nvim"
        }
    }
	use {
		"ellisonleao/gruvbox.nvim"
    }
	use('nvim-treesitter/nvim-treesitter', {run = ':TSUpdate'})
	use('nvim-treesitter/playground')
	use {
		'VonHeikemen/lsp-zero.nvim',
		branch = 'v3.x',
		requires = {


            -- LSP Support
            {"williamboman/mason.nvim",},
            {"williamboman/mason-lspconfig.nvim"},
            {"neovim/nvim-lspconfig"},
            {'neovim/nvim-lspconfig'},
            -- Autocompletion
            {'hrsh7th/nvim-cmp'},
            {'hrsh7th/cmp-buffer'},
            {'hrsh7th/cmp-path'},
            {'hrsh7th/cmp-cmdline'},
            {'hrsh7th/cmp-nvim-lsp'},

            {'L3MON4D3/LuaSnip'},
            {'rafamadriz/friendly-snippets'},
        }
    }
    use {
        'mfussenegger/nvim-dap',
        'rcarriga/nvim-dap-ui',
        'theHamsta/nvim-dap-virtual-text',
        'leoluz/nvim-dap-go',
    }
    use {
        'nvim-lualine/lualine.nvim',
        requires = { 'nvim-tree/nvim-web-devicons', opt = true }
    }
    use {
        'numToStr/Comment.nvim',
        config = function()
            require('Comment').setup()
        end
    }
    -- Lua
    use {
        "folke/which-key.nvim",
        config = function()
            vim.o.timeout = true
            vim.o.timeoutlen = 300
            require("which-key").setup {
            }
        end
    }
    use {
        "windwp/nvim-autopairs",
        config = function() require("nvim-autopairs").setup {} end
    }
    use {
        'romgrk/barbar.nvim',
        'lewis6991/gitsigns.nvim',
        'nvim-tree/nvim-web-devicons',
    }
    use {
        'WhoIsSethDaniel/toggle-lsp-diagnostics.nvim',
    }
    use {
        'kawre/leetcode.nvim', {run=":TSUpdate html"},
        requires = {
            'nvim-telescope/telescope.nvim',
            'nvim-lua/plenary.nvim',
            'MunifTanjim/nui.nvim',

            -- optional
            -- 'nvim-treesitter/nvim-treesitter',
            -- 'rcarriga/nvim-notify',
            -- 'nvim-tree/nvim-web-devicons'
        }
    }
end)

Infinite loop fetching problem list

Attempting to fetch the problems list on a fresh install of leetcode.nvim results in an infinite loop of "leetcode.nvim fetching problem list" and the following error message:

E5108: Error executing lua: ...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:18: The coroutine failed with this message: ...im/lazy/leetcode.nvim/lua/leetcode/cache/problemlist.lua:61: attempt to index local 'err' (a nil value)
stack traceback:
[C]: in function 'error'
...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:18: in function 'callback_or_next'
...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:45: in function 'step'
...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:48: in function 'execute'
...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:108: in function 'run'
...re/nvim/lazy/leetcode.nvim/lua/leetcode/command/init.lua:29: in function <...re/nvim/lazy/leetcode.nvim/lua/leetcode/command/init.lua:23>

Start without running with arg

I have functions in my config that rely on argc/argv (related to session management), and I do a lot of lazy loading in my as well. These two things mean that it's not convenient or feasible for me to launch leetcode.nvim from the commandline, since (1) the plugin is not loaded before VimEnter and (2) opening nvim with an argument overwrites my current session for the cwd. I also just prefer the flow of typing the command after opening nvim vs. adding an argument.

It would be nice to just have the Leet command available when the plugin is loaded so that it can be started from a running nvim session, and have the starting with argument be optional.

Happy to contribute a PR for this, just figured I'd open an issue first to see if this change is something you'd be open to.

Python3 lang still uses Python2

The python3 question template is the same as the python2 (python) one and code that runs on python3 on leetcode.com doesn't run on leetcode.nvim when python3 is selected as the language.

Problem List issues

If your problem list is not loading correctly after updating leetcode.nvim, it's because i've updated the structure of it. To fix it either go to Menu > Cache > Update or delete .problemlist in leetcode.nvim home directory so it automatically gets updated next time you try to access it.

Cannot Use

Sorry This might be silly, but I simply cannot use this plugin after I installed it with packer.nvim. When I do nvim leetcode.nvim, I just got an new file named leetcode.nvim and start to edit it with nvim. I have checked the installation by packer status and it is successfully installed.

Error when running nvim leetcode.nvim

Error executing vim.schedule lua callback: .../share/nvim/lazy/leetcode.nvim/lua/leetcode/api/auth.lua:9: attempt to index lo
cal 'res' (a nil value)
stack traceback:
        .../share/nvim/lazy/leetcode.nvim/lua/leetcode/api/auth.lua:9: in function 'update_cfg_auth'
        .../share/nvim/lazy/leetcode.nvim/lua/leetcode/api/auth.lua:53: in function 'cb'
        ...share/nvim/lazy/leetcode.nvim/lua/leetcode/api/utils.lua:83: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

I'm getting this error when I try to run leetcode.nvim.

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

        "nvim-tree/nvim-web-devicons",
        "rcarriga/nvim-notify",
    },
    opts = {
        console = {
            open_on_runcode = true,
            size = {
                width = "100%", ---@type string | integer
                height = "95%", ---@type string | integer
            },
            dir = "row", ---@type "col" | "row"
        },
        lang = "python3",
        description = {
            width = "100%", ---@type string | integer
        }
    },
    config = function(_, opts)
        vim.keymap.set("n", "<leader>lq", "<cmd>LcQuestionTabs<cr>")
        vim.keymap.set("n", "<leader>lm", "<cmd>LcMenu<cr>")
        vim.keymap.set("n", "<leader>lc", "<cmd>LcConsole<cr>")
        vim.keymap.set("n", "<leader>ll", "<cmd>LcLanguage<cr>")
        vim.keymap.set("n", "<leader>ld", "<cmd>LcDescriptionToggle<cr>")
        vim.keymap.set("n", "<leader>lr", "<cmd>LcRun<cr>")
        vim.keymap.set("n", "<leader>ls", "<cmd>LcSubmit<cr>")
        require("leetcode").setup(opts)
    end,
}

Here is my setup.

Error on startup regarding nvim_get_hl()

I'm getting the following error when trying to run the plugin using nvim leetcode.nvim.

Failed to run `config` for leetcode.nvim
...in/.local/share/nvim/lazy/leetcode.nvim/lua/leetcode.lua:28: attempt to call field 'nvim_get_hl' (a nil value)
# stacktrace:
  - /leetcode.nvim/lua/leetcode.lua:28 _in_ **setup_highlights**
  - /leetcode.nvim/lua/leetcode.lua:59 _in_ **start**
  - /leetcode.nvim/lua/leetcode.lua:68 _in_ **setup**
  - ~/.config/nvim/lua/config/lazy.lua:12

This is my lazy config for the plugin

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

		-- optional
		"nvim-tree/nvim-web-devicons",

		-- recommended
		-- "rcarriga/nvim-notify",
	},
	opts = {
		-- configuration goes here
	},
}

Invalid cookie when sign in

Hi, when I sign in to leetcode by Cookie, I get an error:
Error executing vim.schedule lua callback: ...packer\start\leetcode.nvim/lua/leetcode/cache/cookie.lua:25: Invalid cookie stack traceback: [C]: in function 'error' ...packer\start\leetcode.nvim/lua/leetcode/cache/cookie.lua:25: in function 'update' ...pack\packer\start\leetcode.nvim/lua/leetcode/command.lua:45: in function 'on_submit' ...a\site\pack\packer\start\nui.nvim/lua/nui/input/init.lua:160: in function <...a\site\pack\packer\start\nui.nvim/lua/nui/input/init.lua:147>
image
image
image

I'm using Windows 11 and packer.nvim.

Indentation of Python code changes upon submission

Hi, I really love this project, but I ran into this bug where the indentation of my Python code became malformed upon submission through the LcConsole, which results in a wrong submission.

$ nvim --version
NVIM v0.10.0-dev-528+g1f8fb7c00
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3

lazy.nvim config:

return {
  "kawre/leetcode.nvim",
  event = "VeryLazy",
  config = true,
}

Here's how the code looks like in neovim:
image

Submission error:
image

How the submitted code looks like:
image

[BUG]: Error occurs when executing run and submit commands

Taking two-sum as an example, when I execute the Leet run or Leet submit command, there will be an error, and there are several types of error messages. I will try to list them all as follows:

Error executing luv callback:
...a/Local/nvim-data/lazy/plenary.nvim/lua/plenary/curl.lua:289: post https://leetcode.cn/problems/two-sum/interpret_solution/ - curl error exit_code=3 stderr={ "curl: (3) bad range in URL position 13:", "data_input:[2,7,11,15]\
\n9\\n[3,2,4]\\n6\\n[3,3]\\n6", "            ^" }
stack traceback:
        [C]: in function 'error'
        ...a/Local/nvim-data/lazy/plenary.nvim/lua/plenary/curl.lua:289: in function '_user_on_exit'
        ...ta/Local/nvim-data/lazy/plenary.nvim/lua/plenary/job.lua:240: in function '_shutdown'
        ...ta/Local/nvim-data/lazy/plenary.nvim/lua/plenary/job.lua:47: in function <...ta/Local/nvim-data/lazy/plenary.nvim/lua/plenary/job.lua:38>
Error executing luv callback:
...a/Local/nvim-data/lazy/plenary.nvim/lua/plenary/curl.lua:289: post https://leetcode.cn/problems/two-sum/interpret_solution/ - curl error exit_code=3 stderr={ "curl: (3) nested brace in URL position 95:", "typed_code:class Sol
ution {\\n  public:\\n    vector<int> twoSum(vector<int> &nums, int target) {\\n        vector<int> result;\\n        unordered_map<int, int> m;\\n\\n        for (int i = 0; i < nums.size(); i++) {\\n            auto iter = m.fi
nd(target - nums[i]);\\n            if (iter != m.end()) {\\n                result.push_back((*iter).second);\\n                result.push_back(i);\\n                return result;\\n            }\\n            m[nums[i]] = i;
\\n        }\\n\\n" }
stack traceback:
        [C]: in function 'error'
        ...a/Local/nvim-data/lazy/plenary.nvim/lua/plenary/curl.lua:289: in function '_user_on_exit'
        ...ta/Local/nvim-data/lazy/plenary.nvim/lua/plenary/job.lua:240: in function '_shutdown'
        ...ta/Local/nvim-data/lazy/plenary.nvim/lua/plenary/job.lua:47: in function <...ta/Local/nvim-data/lazy/plenary.nvim/lua/plenary/job.lua:38>
Error executing luv callback:
...a/Local/nvim-data/lazy/plenary.nvim/lua/plenary/curl.lua:289: post https://leetcode.cn/problems/two-sum/interpret_solution/ - curl error exit_code=3 stderr={ "curl: (6) Could not resolve host: question_id", "curl: (3) URL rej
ected: Port number was not a decimal number between 0 and 65535", "curl: (3) nested brace in URL position 95:", "typed_code:class Solution {\\n  public:\\n    vector<int> twoSum(vector<int> &nums, int target) {\\n        vector<
int> result;\\n        unordered_map<int, int> m;\\n\\n        for (int i = 0; i < nums.size(); i++) {\\n            auto iter = m.find(target - nums[i]);\\n            if (iter != m.end()) {\\n                result.push_back((
*iter).second);\\n                result.push_back(i);\\n                return result;\\n            }\\n            m[nums[i]] = i;\\n        }\\n\\n" }
stack traceback:
        [C]: in function 'error'
        ...a/Local/nvim-data/lazy/plenary.nvim/lua/plenary/curl.lua:289: in function '_user_on_exit'
        ...ta/Local/nvim-data/lazy/plenary.nvim/lua/plenary/job.lua:240: in function '_shutdown'
        ...ta/Local/nvim-data/lazy/plenary.nvim/lua/plenary/job.lua:47: in function <...ta/Local/nvim-data/lazy/plenary.nvim/lua/plenary/job.lua:38>
Error executing luv callback:
...a/Local/nvim-data/lazy/plenary.nvim/lua/plenary/curl.lua:289: post https://leetcode.cn/problems/two-sum/interpret_solution/ - curl error exit_code=3 stderr={ "curl: (3) URL rejected: Port number was not a decimal number betwe
en 0 and 65535", "curl: (3) bad range in URL position 13:", "data_input:[2,7,11,15]\\n9\\n[3,2,4]\\n6\\n[3,3]\\n6", "            ^" }
stack traceback:
        [C]: in function 'error'
        ...a/Local/nvim-data/lazy/plenary.nvim/lua/plenary/curl.lua:289: in function '_user_on_exit'
        ...ta/Local/nvim-data/lazy/plenary.nvim/lua/plenary/job.lua:240: in function '_shutdown'
        ...ta/Local/nvim-data/lazy/plenary.nvim/lua/plenary/job.lua:47: in function <...ta/Local/nvim-data/lazy/plenary.nvim/lua/plenary/job.lua:38>

The environment is Windows 11, and the following is the code content:

#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

// @leet start
class Solution {
  public:
    vector<int> twoSum(vector<int> &nums, int target) {
        vector<int> result;
        unordered_map<int, int> m;

        for (int i = 0; i < nums.size(); i++) {
            auto iter = m.find(target - nums[i]);
            if (iter != m.end()) {
                result.push_back((*iter).second);
                result.push_back(i);
                return result;
            }
            m[nums[i]] = i;
        }

        return result;
    }
};
// @leet end

Feature request: Ability to hide difficulty and solve rate

It would be awesome if we could disable the difficulty level, like ratio and solve rate of the problem. I know this isn't a feature most people would use but it would be really useful for those who want it.
Screenshot 2023-11-24 at 10 36 43โ€ฏPM
Thank you for the wonderful plugin.

Open console when running or submitting directly from the editor.

Hey, I think a good feature would be to include an option to toggle the console when running or submitting code with the LcRun or LcSubmit commands. It was simple enough so a newbie like me could do it, and I would be happy to open a pull request if you think it's something worth adding. Thank you for this great plugin :)

Error in rust to activate LSP

Hi, when i try to solve a proble of leetcode in rust, the lsp feature doesn't activate
image
this is the LspInfo:
`Language client log: /home/gus/.local/state/nvim/lsp.log
Detected filetype: rust

1 client(s) attached to this buffer:

Client: null-ls (id: 1, bufnr: [8])
filetypes: toml, c, java, cuda, cs, proto, cpp, rust, html, typescriptreact, javascriptreact, typescript, svelte, vue, javascript, luau, lua, python
autostart: false
root directory: /media/gus/proyectos/leetcode
cmd:

Other clients that match the filetype: rust

Config: rust_analyzer
filetypes: rust
root directory: Not found.
cmd: /home/gus/.local/share/nvim/mason/bin/rust-analyzer
cmd is executable: true
autostart: true
custom handlers: experimental/serverStatus
`
and whe i open the file with normal neovim the lsp works perfectly
image

`

Language client log: /home/gus/.local/state/nvim/lsp.log
Detected filetype: rust

2 client(s) attached to this buffer:

Client: null-ls (id: 1, bufnr: [1])
filetypes: toml, python, javascript, vue, html, typescriptreact, javascriptreact, svelte, typescript, rust, luau, lua, java, c, cpp, cuda, cs, proto
autostart: false
root directory: /media/gus/proyectos/leetcode
cmd:

Client: rust_analyzer-standalone (id: 2, bufnr: [1])
filetypes: rust
autostart: false
root directory: /media/gus/proyectos/leetcode
cmd: rust-analyzer

Other clients that match the filetype: rust

Config: rust_analyzer
filetypes: rust
root directory: Not found.
cmd: /home/gus/.local/share/nvim/mason/bin/rust-analyzer
cmd is executable: true
autostart: true
custom handlers: experimental/serverStatus

`

[Feature request] Allow choosing, creating, and deleting sessions

I noticed that the only option missing from the main menu is the ability to choose, create, and delete a session from a currently logged in user account. Adding this as a feature will make this plugin more complete and save more clicks for anyone who does utilize multiple sessions in their account, as they will no longer have to do these things through the browser while leaving the plugin open.

I'm willing to work on this feature and make a PR. The changes required don't seem to complicated as far as I can tell.

Error on submission

Error executing vim.schedule lua callback: ...as/.local/share/nvim/lazy/nui.nvim/lua/nui/line/init.lua:22: attempt to index local 'block' (a nil value)
stack traceback:
        ...as/.local/share/nvim/lazy/nui.nvim/lua/nui/line/init.lua:22: in function 'append'
        ...im/lazy/leetcode.nvim/lua/leetcode/ui/console/result.lua:69: in function 'handle_runtime'
        ...im/lazy/leetcode.nvim/lua/leetcode/ui/console/result.lua:210: in function 'unknown'
        ...im/lazy/leetcode.nvim/lua/leetcode/ui/console/result.lua:244: in function 'handle'
        ...are/nvim/lazy/leetcode.nvim/lua/leetcode/runner/init.lua:42: in function 'callback'
        ...are/nvim/lazy/leetcode.nvim/lua/leetcode/runner/init.lua:27: in function 'callback'
        ...nvim/lazy/leetcode.nvim/lua/leetcode/api/interpreter.lua:28: in function 'cb'
        ...share/nvim/lazy/leetcode.nvim/lua/leetcode/api/utils.lua:58: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

Even with the error the submission is still being processed in the leetcode I can see it reached there but In the editor I have this error.

image

$ nvim --version
NVIM v0.9.2
Build type: Release
LuaJIT 2.1.1692716794

my init.lua

vim.cmd[[filetype plugin indent on]]
vim.cmd[[syntax on]]

vim.cmd[[set autoindent]]
vim.cmd[[set background=light]]
vim.cmd[[set backspace=indent,eol,start]]
vim.cmd[[set clipboard=unnamedplus]] 
vim.cmd[[set expandtab]]
vim.cmd[[set foldopen-=search]]
vim.cmd[[set guicursor=]]
vim.cmd[[set hidden]]
vim.cmd[[set ignorecase]]
vim.cmd[[set incsearch]]
vim.cmd[[set laststatus=0]]
vim.cmd[[set nobackup]]
vim.cmd[[set noswapfile]]
vim.cmd[[set nowrap]]
vim.cmd[[set ruler]]
vim.cmd[[set scrolloff=999]]
vim.cmd[[set shiftwidth=4]]
vim.cmd[[set shortmess-=S]]
vim.cmd[[set smartcase]]
vim.cmd[[set softtabstop=4]]
vim.cmd[[set tabstop=4]]
vim.cmd[[set termguicolors]]
vim.cmd[[set ttimeout]]
vim.cmd[[set ttimeoutlen=100]]

vim.cmd[[let mapleader = " "]]
vim.cmd[[nnoremap <leader><space> :Telescope buffers<CR>]]
vim.cmd[[nnoremap <leader>c :cd %<CR>]]
vim.cmd[[nnoremap <leader>e :E<CR>]]
vim.cmd[[nnoremap <leader>f :Telescope find_files<CR>]]
vim.cmd[[nnoremap <leader>g :Telescope live_grep<CR>]]
vim.cmd[[nnoremap <leader>n :cn<CR>]]
vim.cmd[[nnoremap <leader>p :cp<CR>]]
vim.cmd[[nnoremap <leader>s :G<CR>]]
vim.cmd[[nnoremap <leader>y :let @+=expand("%") . ':' . line(".")<CR>]]

vim.cmd[[noremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<CR>"]]
vim.cmd[[noremap <expr> <S-TAB> pumvisible() ? "\<C-p>" : "\<TAB>"]]
vim.cmd[[noremap <expr> <TAB> pumvisible() ? "\<C-n>" : "\<TAB>"]]
vim.cmd[[noremap <leader>ca :LspCodeAction<CR>]]
vim.cmd[[noremap <leader>rn :LspRename<CR>]]
vim.cmd[[noremap K :LspHover<CR>]]
vim.cmd[[noremap [d :LspDiagPrev<CR>]]
vim.cmd[[noremap ]d :LspDiagNext<CR>]]
vim.cmd[[noremap gd :LspGotoDefinition<CR>]]
vim.cmd[[noremap gr :LspShowReferences<CR>]]

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({
        "git",
        "clone",
        "--filter=blob:none",
        "https://github.com/folke/lazy.nvim.git",
        "--branch=stable",
        lazypath,
    })
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({

    'tpope/vim-fugitive',
    'MunifTanjim/nui.nvim',
    'nvim-treesitter/nvim-treesitter',
    {
        'nvim-telescope/telescope.nvim', tag = '0.1.3',
        dependencies = { 'nvim-lua/plenary.nvim' }
    },

    "ellisonleao/gruvbox.nvim",
    "kawre/leetcode.nvim",

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

            "nvim-tree/nvim-web-devicons",
            "rcarriga/nvim-notify",
        },
        opts = {
            domain = "com",
            arg = "leetcode.nvim",
            lang = "golang",

        },
        config = function(_, opts)
            vim.keymap.set("n", "<leader>lq", "<cmd>LcQuestionTabs<cr>")
            vim.keymap.set("n", "<leader>lm", "<cmd>LcMenu<cr>")
            vim.keymap.set("n", "<leader>lc", "<cmd>LcConsole<cr>")
            vim.keymap.set("n", "<leader>ll", "<cmd>LcLanguage<cr>")
            vim.keymap.set("n", "<leader>ld", "<cmd>LcDescriptionToggle<cr>")
            require("leetcode").setup(opts)
        end,
    }
})

vim.cmd[[let g:netrw_list_hide='\(^\|\s\s\)\zs\.\S\+']]
vim.cmd[[let g:netrw_banner=0]]

require("gruvbox").setup({})
vim.cmd[[colorscheme gruvbox]]

require'nvim-treesitter.configs'.setup {
    ensure_installed = { "c", "lua", "vim", "vimdoc", "query", "html", "go", "ruby" },
}

Unable to authenticate

image

When I am logging in the api returns meta name as robot and I am unable to login. Even after doing :Leet fix and re-signing using the cookie it takes me to the menu but is unable to fetch problems with error user not signed in

image

Also, when I open leetcode on browser as well it is making me check I am not a robot checkbox.

Can't Sign in Using CSRF Token

It seems like leetcode have updated their LEETCODE_SESSION token, I've also tried using csrftoken but it doesn't work
bad csrf token format. I'm using firefox
image

leetcode.cn cannot sign in

image

Hello there. I'm always getting this error, and i have already set cn as enabled.

image

Kinda weird and i don't know what to do rn...

[Feature Request]: buffer create callback

Because the solving-problem buffer this plugin created has a normal file type (that is what language the user prefers), it is hard to distinguish this buffer from others, so it is hard to define specific keymaps for these buffers only.

It would be useful if there's a callback function with a buffer number as an argument, and users could leverage this function to define the keymaps or other buffer-specific options(disabling copilot in these buffers would also be useful).

Hook on opening

Is it possible to add a configuration hook so that when you run nvim leetcode.nvim it will trigger a function. I think this functionally would be useful for people who want to disable plugins before coding. For example, I want to disable Copilot before writing code.

Leet run, test, submit respond with http error 499

Writing this incase someone else comes into this issue

I copied the cookie from firefox 88.0 and I experience these issues but when copying from chrome 121.0.6167.160 it now works.

The keys that I'm using now that seem to work that were copied from chrome are these:
cf_clearance
csrftoken
LEETCODE_SESSION

Screenshot from 2024-03-03 23-43-03

injector not working for python3

Hi @kawre and sorry to disturb you, recently i just use your plugin to do my leetcode exercise but i found that when I use python3 as a language is not work when comes to List (doesn't import at the starting point)

return {
	"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
		lang = "python3",
		injector = { ---@type table<lc.lang, lc.inject>
			["python"] = {
				before = "from typing import List",
			},

			["python3"] = {
				before = "from typing import List",
			},
		},
	},
}

Problem not showing the code suggestion since List is not imported
Screenshot 2024-01-31 at 9 22 23 PM

'win' cannot be passed for buffer-local option 'filetype'

          Not sure what changed, but after nvim update and LazyVim and lazyvim.nvim update, now even `nvim leetcode.nvim` doesn't work. 
 {
    "kawre/leetcode.nvim",
    build = ":TSUpdate html",
    dependencies = {
      "MunifTanjim/nui.nvim",
      "nvim-lua/plenary.nvim", -- required by telescope
      "nvim-telescope/telescope.nvim",
      "nvim-tree/nvim-web-devicons",
      "nvim-treesitter/nvim-treesitter",
      "rcarriga/nvim-notify",
    },
    opts = {
      lang = "rust",
      -- sql = "postgresql"
    },
    config = function(_, opts)
      vim.keymap.set("n", "<leader>lq", "<cmd>LcQuestionTabs<cr>")
      vim.keymap.set("n", "<leader>lm", "<cmd>LcMenu<cr>")
      vim.keymap.set("n", "<leader>lc", "<cmd>LcConsole<cr>")
      vim.keymap.set("n", "<leader>ll", "<cmd>LcLanguage<cr>")
      vim.keymap.set("n", "<leader>ld", "<cmd>LcDescriptionToggle<cr>")

      require("leetcode").setup(opts)
    end,
  },

is my setup.

After adding event = "BufEnter" for leetcode.nvim in my setup above, I see this:

Error executing lua callback: ...hare/nvim/lazy/leetcode.nvim/lua/leetcode-menu/utils.lua:10: 'win' cannot be passed for buffer-local option 'filetype'
stack traceback:
	[C]: in function 'nvim_set_option_value'
	...hare/nvim/lazy/leetcode.nvim/lua/leetcode-menu/utils.lua:10: in function 'apply_opt_local'
	...share/nvim/lazy/leetcode.nvim/lua/leetcode-menu/init.lua:120: in function 'init'
	...tu/.local/share/nvim/lazy/leetcode.nvim/lua/leetcode.lua:61: in function 'start'
	...tu/.local/share/nvim/lazy/leetcode.nvim/lua/leetcode.lua:72: in function <...tu/.local/share/nvim/lazy/leetcode.nvim/lua/leetcode.lua:72>

Originally posted by @surmish in #10 (comment)

How would I actually map Leet commands?

According to lazyvim, i should I add keys in this way, but those commands are not appearing in my command list...

return {
  {
    "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",
    },
    keys = {
        { "<leader>lq", "<cmd>Leet list<cr>", desc = "List Questions" },
        { "<leader>ll", "<cmd>Leet desc<cr>", desc = "View Question" },
        { "<leader>lt", "<cmd>Leet run<cr>", desc = "Run Code" },
        { "<leader>ls", "<cmd>Leet submit<cr>", desc = "Submit Code" },
    },
    opts = {}
    }
}

Some image issues

Thank you for the awesome new feature! Some minor issues:
Line wrap gets set to off again by default in the problem tab, which can be fixed by focusing the problem buffer and setting wrap to true.
The image stays rendered when the console opens up. That's weird because it doesn't stay in focus when regular telescope opens up.
Screenshot 2023-11-14 at 4 52 00โ€ฏPM

Keybinding to move between tests and results in console

Hi,
First of all, this is a well-thought-out and well-made plugin and is the main reason why I'm spending so much time on LC. I can't thank you enough!

I couldn't find it if it is there already, but it'd be great to add a keybinding to move between Tests and Results windows in the console to copy test cases. It'd be great if you could display it below along with (r) Reset.

Automatically wrapping the description

The description/problem statements usually contain long lines that end up hiding behind the split. I fixed this issue by running :set wrap in the description buffer, but, this is an inconvenient step that should be handled by the plugin. If not the default mode, there should be an option for it in the config.

Respect tabs/spaces settings

I have tabs set to spaces and set to 2. This gets overwritten however when I am programming in python.

My init.lua loads plugins before keymaps, since I have some keymaps that are dependent on plugins.

Weird login screen

2023-10-12-22-38-51

Hello there. Hope you're doing well. Thank you for creating this plugin because their vim emulator sucks big time.

However, my start-up screen looks weird. Is this an issue on my end? Thank you!

Command to Reset all solutions?

I use leetcode to do kata everyday. When I open question, i do not want to see my previous solution. I know there is command to reset only current problem(Leet reset), is there any possibility to reset all problems?

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.