Skip to content

update #79

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

Merged
merged 1 commit into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## version 2.8.1

- 插入头文件,解决避免都是红色波浪线语法提示

## version 2.7.3

- 某些情况下颜色对比显示错误
Expand Down
73 changes: 72 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-leetcode-problem-rating",
"displayName": "LeetCode",
"description": "LeetCode 官方插件增强, 代码开源, 增加 LeetCode 题目难度分, 给个star吧, 球球了",
"version": "2.7.3",
"version": "2.8.1",
"author": "ccagml",
"publisher": "ccagml",
"license": "MIT",
Expand Down Expand Up @@ -242,6 +242,11 @@
"command": "lcpr.removeQidFromGroup",
"title": "从分类中移除这个题目",
"icon": "$(remove)"
},
{
"command": "lcpr.includeTemplates",
"title": "插入头文件模板",
"icon": "$(remove)"
}
],
"viewsContainers": {
Expand Down Expand Up @@ -568,6 +573,72 @@
{
"title": "leetcode-problem-rating",
"properties": {
"leetcode-problem-rating.includeTemplates": {
"type": "array",
"description": "引入一些默认内容,防止vscode都是波浪红线",
"default": [
{
"language": "cpp",
"template": [
"using namespace std;",
"#include <algorithm>",
"#include <array>",
"#include <bitset>",
"#include <climits>",
"#include <deque>",
"#include <functional>",
"#include <iostream>",
"#include <list>",
"#include <queue>",
"#include <stack>",
"#include <tuple>",
"#include <unordered_map>",
"#include <unordered_set>",
"#include <utility>",
"#include <vector>"
]
}
],
"items": {
"type": "object",
"required": [
"language"
],
"properties": {
"language": {
"type": "string",
"enum": [
"bash",
"c",
"cpp",
"csharp",
"golang",
"java",
"javascript",
"kotlin",
"mysql",
"php",
"python",
"python3",
"ruby",
"rust",
"scala",
"swift",
"typescript"
],
"description": "哪种语言"
},
"template": {
"type": "array",
"default": [],
"description": "模板内容",
"items": {
"type": "string"
}
}
}
}
},
"leetcode-problem-rating.hideSolved": {
"type": "boolean",
"default": false,
Expand Down
3 changes: 3 additions & 0 deletions src/controller/RemarkController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class RemarkController implements Disposable {
public async startRemark(document: TextDocument) {
await remarkService.startRemark(document);
}
public async includeTemplates(document: TextDocument) {
await remarkService.includeTemplates(document);
}

public remarkCancelsaveNote(comment: RemarkComment) {
remarkService.remarkCancelsaveNote(comment);
Expand Down
3 changes: 3 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ export async function activate(context: ExtensionContext): Promise<void> {
}),
commands.registerCommand("lcpr.startRemark", (document: TextDocument) => {
remarkController.startRemark(document);
}),
commands.registerCommand("lcpr.includeTemplates", (document: TextDocument) => {
remarkController.includeTemplates(document);
})
);

Expand Down
5 changes: 5 additions & 0 deletions src/service/FileButtonService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ export class FileButtonService implements vscode.CodeLensProvider {
title: "remark",
command: "lcpr.startRemark",
arguments: [document],
}),
new vscode.CodeLens(range, {
title: "includeTemplates",
command: "lcpr.includeTemplates",
arguments: [document],
})
);
return temp_result;
Expand Down
22 changes: 22 additions & 0 deletions src/service/RemarkService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ import {
comments,
Range,
Disposable,
window,
Position,
} from "vscode";
import { treeViewController } from "../controller/TreeViewController";
import { remarkDao } from "../dao/remarkDao";
import { RemarkComment } from "../model/Model";
import { getIncludeTemplate } from "../utils/ConfigUtils";

class RemarkService implements Disposable {
private _remarkComment;
Expand Down Expand Up @@ -44,6 +47,25 @@ class RemarkService implements Disposable {
};
}

public async includeTemplates(document: TextDocument) {
const content: string = document.getText();
const matchResult: RegExpMatchArray | null = content.match(/@lc app=.* id=(.*) lang=(.*)/);
if (!matchResult || !matchResult[2]) {
return undefined;
}
for (let i: number = 0; i < document.lineCount; i++) {
const lineContent: string = document.lineAt(i).text;

if (lineContent.indexOf("@lc code=start") >= 0) {
const editor = window.activeTextEditor;
editor?.edit((edit) => {
edit.insert(new Position(i - 1, i - 1), getIncludeTemplate(matchResult[2]));
});
}
}
return undefined;
}

public async startRemark(document: TextDocument) {
let docInfo = this.getQidByDocument(document);
if (docInfo["qid"] == undefined) {
Expand Down
13 changes: 13 additions & 0 deletions src/utils/ConfigUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,16 @@ export async function setDefaultLanguage(): Promise<void> {
export function isAnswerDiffColor(): boolean {
return getVsCodeConfig().get<boolean>("answerDiffColor", false);
}

export function getIncludeTemplate(lang: string): string {
let temp_cfg = getVsCodeConfig().get<any>("includeTemplates") || [];
let result = "";
temp_cfg.forEach((element) => {
if (element.language == lang) {
result = (element.template || []).join("\n");
return;
}
});

return result;
}