kawre / leetcode.nvim

A Neovim plugin enabling you to solve LeetCode problems.
MIT License
655 stars 34 forks source link

How can I resolve these errors? #30

Closed Penguin-SAMA closed 7 months ago

Penguin-SAMA commented 7 months ago

I am using C++, how can I fix the issue where vector and ListNode are not recognized? Can it only be done manually? image

kawre commented 7 months ago

you need to import them at the top so the LSP will be aware of them

Penguin-SAMA commented 7 months ago

But if I add a structure like ListNode, I can't solve the problem correctly. image

kawre commented 7 months ago

LeetCode has it own compiler, whereas you can see ListNode is already defined. Just because you are getting an error in your neovim doesn't mean that the test will not pass.

If i remember correctly ListNode is the only custom struct i came across using LeetCode. For example, if you are using java, you can create an object inside leetcode.nvim home directory named ListNode, solely for auto completion purposes. I don't know if it will work the same way with cpp, but you can always uncomment the struct, and then if you are about to run/submit, comment it again so it won't clash with the LeetCode compiler.

Penguin-SAMA commented 7 months ago

I know that commenting out the structure allows me to solve the problem correctly, but this looks very inelegant, so I want to ask for a possible solution. However, if it's just ListNode causing this issue, it seems acceptable. Anyway, thank you very much for your patient response.

kawre commented 7 months ago
#include "./ListNode.cpp"
#include <cstddef>

// @leet start
class Solution
{
  public:
    ListNode *reverseList(ListNode *head)
    {

        ListNode *prev = NULL;
        ListNode *curr = head;

        while (curr != NULL)
        {
            ListNode *forward = curr->next;
            curr->next = prev;
            prev = curr;
            curr = forward;
        }
        return prev;
    }
};
// @leet end

@Penguin-SAMA Now only the code within @leet tags gets submitted. So you can do something like

#include "./ListNode.cpp"

to have auto completion from local files or have a place to define a struct.

Penguin-SAMA commented 4 months ago

The latest version seems to no longer display @leet start and @leet end.

image

kawre commented 4 months ago

Thanks for the report, should be working now