Skip to content

Commit fda8187

Browse files
committed
添加markdown高亮
1 parent f83d161 commit fda8187

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
"type": "string",
3737
"default": "",
3838
"description": "DeepSeek API Key"
39+
},
40+
"codeReDesign.treatCvbAsMarkdown": {
41+
"type": "boolean",
42+
"default": true,
43+
"description": "Treat .cvb files as Markdown"
3944
}
4045
}
4146
}

src/cvbMarkdownHandler.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import * as vscode from 'vscode';
2+
3+
export function setupCvbAsMarkdown(context: vscode.ExtensionContext) {
4+
const config = vscode.workspace.getConfiguration('codeReDesign');
5+
const treatCvbAsMarkdown = config.get('treatCvbAsMarkdown', true);
6+
7+
const originalLanguages: { [key: string]: string } = {};
8+
9+
function setLanguageForCvbDocuments(enabled: boolean) {
10+
vscode.workspace.textDocuments.forEach(doc => {
11+
if (doc.fileName.endsWith('.cvb')) {
12+
if (enabled) {
13+
originalLanguages[doc.uri.toString()] = doc.languageId;
14+
vscode.languages.setTextDocumentLanguage(doc, 'markdown');
15+
} else {
16+
const originalLanguage = originalLanguages[doc.uri.toString()];
17+
if (originalLanguage) {
18+
vscode.languages.setTextDocumentLanguage(doc, originalLanguage);
19+
delete originalLanguages[doc.uri.toString()];
20+
}
21+
}
22+
}
23+
});
24+
}
25+
26+
if (treatCvbAsMarkdown) {
27+
setLanguageForCvbDocuments(true);
28+
29+
const openDocumentListener = vscode.workspace.onDidOpenTextDocument(document => {
30+
if (document.fileName.endsWith('.cvb')) {
31+
originalLanguages[document.uri.toString()] = document.languageId;
32+
vscode.languages.setTextDocumentLanguage(document, 'markdown');
33+
}
34+
});
35+
context.subscriptions.push(openDocumentListener);
36+
}
37+
38+
config.onDidChange((e: vscode.ConfigurationChangeEvent) => {
39+
if (e.affectsConfiguration('codeReDesign.treatCvbAsMarkdown')) {
40+
const newValue = config.get('treatCvbAsMarkdown', true);
41+
setLanguageForCvbDocuments(newValue);
42+
}
43+
}, null, context.subscriptions);
44+
}

src/extension.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as fs from 'fs';
44
import { selectFiles } from './fileSelector';
55
import { generateCvb, parseCvb, applyCvbToWorkspace } from './cvbManager';
66
import { callDeepSeekApi } from './deepseekApi';
7+
import { setupCvbAsMarkdown } from './cvbMarkdownHandler';
78

89
// 插件激活时调用
910
export function activate(context: vscode.ExtensionContext) {
@@ -133,6 +134,8 @@ export function activate(context: vscode.ExtensionContext) {
133134
});
134135

135136
context.subscriptions.push(generateCvbCommand, uploadCvbCommand, applyCvbCommand, outputChannel);
137+
138+
setupCvbAsMarkdown(context);
136139
}
137140

138141
// 插件停用时调用

0 commit comments

Comments
 (0)