Skip to content

[FEAT] Auto include & extract definations for cpp and some other languages. #1010

@BeiChenStanly

Description

@BeiChenStanly

Auto include & extract definations

For example, the problem "2.add-two-numbers", the default codes are

/*
 * @lc app=leetcode.cn id=2 lang=cpp
 *
 * [2] add-two-numbers
 */
// @lc code=start
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
        
    }
};
// @lc code=end

After including & extracting definations, we can get

/*
 * @lc app=leetcode.cn id=2 lang=cpp
 *
 * [2] add-two-numbers
 */
#include <bits/stdc++.h>
using namespace std;
struct ListNode {
    int val;
    ListNode *next;
    ListNode() : val(0), next(nullptr) {}
    ListNode(int x) : val(x), next(nullptr) {}
    ListNode(int x, ListNode *next) : val(x), next(next) {}
};
// @lc code=start
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
        
    }
};
// @lc code=end

And we can set auto included files in the settings page. In this example, it is "bits/stdc++.h".

Motivation

It can save some time for those problems.

Contribution

We can add settings and use regex to match the codes in the block comment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions