Skip to content

Commit 321eb93

Browse files
committed
update
1 parent 157ec2b commit 321eb93

File tree

7 files changed

+122
-1
lines changed

7 files changed

+122
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## version 2.8.1
2+
3+
- 插入头文件,解决避免都是红色波浪线语法提示
4+
15
## version 2.7.3
26

37
- 某些情况下颜色对比显示错误

package.json

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-leetcode-problem-rating",
33
"displayName": "LeetCode",
44
"description": "LeetCode 官方插件增强, 代码开源, 增加 LeetCode 题目难度分, 给个star吧, 球球了",
5-
"version": "2.7.3",
5+
"version": "2.8.1",
66
"author": "ccagml",
77
"publisher": "ccagml",
88
"license": "MIT",
@@ -242,6 +242,11 @@
242242
"command": "lcpr.removeQidFromGroup",
243243
"title": "从分类中移除这个题目",
244244
"icon": "$(remove)"
245+
},
246+
{
247+
"command": "lcpr.includeTemplates",
248+
"title": "插入头文件模板",
249+
"icon": "$(remove)"
245250
}
246251
],
247252
"viewsContainers": {
@@ -568,6 +573,72 @@
568573
{
569574
"title": "leetcode-problem-rating",
570575
"properties": {
576+
"leetcode-problem-rating.includeTemplates": {
577+
"type": "array",
578+
"description": "引入一些默认内容,防止vscode都是波浪红线",
579+
"default": [
580+
{
581+
"language": "cpp",
582+
"template": [
583+
"using namespace std;",
584+
"#include <algorithm>",
585+
"#include <array>",
586+
"#include <bitset>",
587+
"#include <climits>",
588+
"#include <deque>",
589+
"#include <functional>",
590+
"#include <iostream>",
591+
"#include <list>",
592+
"#include <queue>",
593+
"#include <stack>",
594+
"#include <tuple>",
595+
"#include <unordered_map>",
596+
"#include <unordered_set>",
597+
"#include <utility>",
598+
"#include <vector>"
599+
]
600+
}
601+
],
602+
"items": {
603+
"type": "object",
604+
"required": [
605+
"language"
606+
],
607+
"properties": {
608+
"language": {
609+
"type": "string",
610+
"enum": [
611+
"bash",
612+
"c",
613+
"cpp",
614+
"csharp",
615+
"golang",
616+
"java",
617+
"javascript",
618+
"kotlin",
619+
"mysql",
620+
"php",
621+
"python",
622+
"python3",
623+
"ruby",
624+
"rust",
625+
"scala",
626+
"swift",
627+
"typescript"
628+
],
629+
"description": "哪种语言"
630+
},
631+
"template": {
632+
"type": "array",
633+
"default": [],
634+
"description": "模板内容",
635+
"items": {
636+
"type": "string"
637+
}
638+
}
639+
}
640+
}
641+
},
571642
"leetcode-problem-rating.hideSolved": {
572643
"type": "boolean",
573644
"default": false,

src/controller/RemarkController.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class RemarkController implements Disposable {
3333
public async startRemark(document: TextDocument) {
3434
await remarkService.startRemark(document);
3535
}
36+
public async includeTemplates(document: TextDocument) {
37+
await remarkService.includeTemplates(document);
38+
}
3639

3740
public remarkCancelsaveNote(comment: RemarkComment) {
3841
remarkService.remarkCancelsaveNote(comment);

src/extension.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ export async function activate(context: ExtensionContext): Promise<void> {
133133
}),
134134
commands.registerCommand("lcpr.startRemark", (document: TextDocument) => {
135135
remarkController.startRemark(document);
136+
}),
137+
commands.registerCommand("lcpr.includeTemplates", (document: TextDocument) => {
138+
remarkController.includeTemplates(document);
136139
})
137140
);
138141

src/service/FileButtonService.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ export class FileButtonService implements vscode.CodeLensProvider {
147147
title: "remark",
148148
command: "lcpr.startRemark",
149149
arguments: [document],
150+
}),
151+
new vscode.CodeLens(range, {
152+
title: "includeTemplates",
153+
command: "lcpr.includeTemplates",
154+
arguments: [document],
150155
})
151156
);
152157
return temp_result;

src/service/RemarkService.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ import {
88
comments,
99
Range,
1010
Disposable,
11+
window,
12+
Position,
1113
} from "vscode";
1214
import { treeViewController } from "../controller/TreeViewController";
1315
import { remarkDao } from "../dao/remarkDao";
1416
import { RemarkComment } from "../model/Model";
17+
import { getIncludeTemplate } from "../utils/ConfigUtils";
1518

1619
class RemarkService implements Disposable {
1720
private _remarkComment;
@@ -44,6 +47,25 @@ class RemarkService implements Disposable {
4447
};
4548
}
4649

50+
public async includeTemplates(document: TextDocument) {
51+
const content: string = document.getText();
52+
const matchResult: RegExpMatchArray | null = content.match(/@lc app=.* id=(.*) lang=(.*)/);
53+
if (!matchResult || !matchResult[2]) {
54+
return undefined;
55+
}
56+
for (let i: number = 0; i < document.lineCount; i++) {
57+
const lineContent: string = document.lineAt(i).text;
58+
59+
if (lineContent.indexOf("@lc code=start") >= 0) {
60+
const editor = window.activeTextEditor;
61+
editor?.edit((edit) => {
62+
edit.insert(new Position(i - 1, i - 1), getIncludeTemplate(matchResult[2]));
63+
});
64+
}
65+
}
66+
return undefined;
67+
}
68+
4769
public async startRemark(document: TextDocument) {
4870
let docInfo = this.getQidByDocument(document);
4971
if (docInfo["qid"] == undefined) {

src/utils/ConfigUtils.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,16 @@ export async function setDefaultLanguage(): Promise<void> {
370370
export function isAnswerDiffColor(): boolean {
371371
return getVsCodeConfig().get<boolean>("answerDiffColor", false);
372372
}
373+
374+
export function getIncludeTemplate(lang: string): string {
375+
let temp_cfg = getVsCodeConfig().get<any>("includeTemplates") || [];
376+
let result = "";
377+
temp_cfg.forEach((element) => {
378+
if (element.language == lang) {
379+
result = (element.template || []).join("\n");
380+
return;
381+
}
382+
});
383+
384+
return result;
385+
}

0 commit comments

Comments
 (0)