Skip to content

Commit

Permalink
🎨
Browse files Browse the repository at this point in the history
  • Loading branch information
Soltus committed Apr 26, 2024
1 parent ca6ba75 commit 4eec7d4
Show file tree
Hide file tree
Showing 33 changed files with 875 additions and 861 deletions.
91 changes: 46 additions & 45 deletions _vscode_plugin/Sillot/src/CodelensProvider.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,56 @@
import * as vscode from 'vscode';
import * as vscode from "vscode";

/**
* CodelensProvider
*/
export class CodelensProvider implements vscode.CodeLensProvider {
private codeLenses: vscode.CodeLens[] = [];
private regex: RegExp;
private _onDidChangeCodeLenses: vscode.EventEmitter<void> = new vscode.EventEmitter<void>();
public readonly onDidChangeCodeLenses: vscode.Event<void> = this._onDidChangeCodeLenses.event;

private codeLenses: vscode.CodeLens[] = [];
private regex: RegExp;
private _onDidChangeCodeLenses: vscode.EventEmitter<void> = new vscode.EventEmitter<void>();
public readonly onDidChangeCodeLenses: vscode.Event<void> = this._onDidChangeCodeLenses.event;
constructor() {
this.regex = /(.+)/g;

constructor() {
this.regex = /(.+)/g;
vscode.workspace.onDidChangeConfiguration(_ => {
this._onDidChangeCodeLenses.fire();
});
}

vscode.workspace.onDidChangeConfiguration((_) => {
this._onDidChangeCodeLenses.fire();
});
}
public provideCodeLenses(
document: vscode.TextDocument,
token: vscode.CancellationToken
): vscode.CodeLens[] | Thenable<vscode.CodeLens[]> {
if (vscode.workspace.getConfiguration("codelens-sample").get("enableCodeLens", true)) {
this.codeLenses = [];
const regex = new RegExp(this.regex);
const text = document.getText();
let matches;
// biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
while ((matches = regex.exec(text)) !== null) {
const line = document.lineAt(document.positionAt(matches.index).line);
const indexOf = line.text.indexOf(matches[0]);
const position = new vscode.Position(line.lineNumber, indexOf);
const range = document.getWordRangeAtPosition(position, new RegExp(this.regex));
if (range) {
this.codeLenses.push(new vscode.CodeLens(range));
}
}
return this.codeLenses;
}
return [];
}

public provideCodeLenses(document: vscode.TextDocument, token: vscode.CancellationToken): vscode.CodeLens[] | Thenable<vscode.CodeLens[]> {

if (vscode.workspace.getConfiguration("codelens-sample").get("enableCodeLens", true)) {
this.codeLenses = [];
const regex = new RegExp(this.regex);
const text = document.getText();
let matches;
// biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
while ((matches = regex.exec(text)) !== null) {
const line = document.lineAt(document.positionAt(matches.index).line);
const indexOf = line.text.indexOf(matches[0]);
const position = new vscode.Position(line.lineNumber, indexOf);
const range = document.getWordRangeAtPosition(position, new RegExp(this.regex));
if (range) {
this.codeLenses.push(new vscode.CodeLens(range));
}
}
return this.codeLenses;
}
return [];
}

public resolveCodeLens(codeLens: vscode.CodeLens, token: vscode.CancellationToken) {
if (vscode.workspace.getConfiguration("codelens-sample").get("enableCodeLens", true)) {
codeLens.command = {
title: "Codelens provided by Sillot",
tooltip: "看什么看",
command: "codelens-sample.codelensAction",
arguments: ["Argument 1", false]
};
return codeLens;
}
return null;
}
public resolveCodeLens(codeLens: vscode.CodeLens, token: vscode.CancellationToken) {
if (vscode.workspace.getConfiguration("codelens-sample").get("enableCodeLens", true)) {
codeLens.command = {
title: "Codelens provided by Sillot",
tooltip: "看什么看",
command: "codelens-sample.codelensAction",
arguments: ["Argument 1", false],
};
return codeLens;
}
return null;
}
}
58 changes: 27 additions & 31 deletions _vscode_plugin/Sillot/src/_dosc.language-configuration.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
{
"comments": {
"lineComment": "//",
"blockComment": ["/*", "*/"]
},
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"]
],
"folding": {
"markers": {
"start": "^\\s*//\\s*#?region\\b",
"end": "^\\s*//\\s*#?endregion\\b"
}
},
"autoClosingPairs": [
{ "open": "{", "close": "}" },
{ "open": "[", "close": "]" },
{ "open": "(", "close": ")" },
{ "open": "'", "close": "'", "notIn": ["string", "comment"] },
{ "open": "\"", "close": "\"", "notIn": ["string"] },
{ "open": "`", "close": "`", "notIn": ["string", "comment"] },
{ "open": "/**", "close": " */", "notIn": ["string"] }
],
"surroundingPairs": [
{"open": "{", "close": "}"},
{"open": "[", "close": "]"},
{"open": "(", "close": ")"},
{"open": "'", "close": "'"},
{"open": "\"", "close": "\""}
]
"comments": {
"lineComment": "//",
"blockComment": ["/*", "*/"]
},
"brackets": [["{", "}"], ["[", "]"], ["(", ")"]],
"folding": {
"markers": {
"start": "^\\s*//\\s*#?region\\b",
"end": "^\\s*//\\s*#?endregion\\b"
}
},
"autoClosingPairs": [
{ "open": "{", "close": "}" },
{ "open": "[", "close": "]" },
{ "open": "(", "close": ")" },
{ "open": "'", "close": "'", "notIn": ["string", "comment"] },
{ "open": "\"", "close": "\"", "notIn": ["string"] },
{ "open": "`", "close": "`", "notIn": ["string", "comment"] },
{ "open": "/**", "close": " */", "notIn": ["string"] }
],
"surroundingPairs": [
{ "open": "{", "close": "}" },
{ "open": "[", "close": "]" },
{ "open": "(", "close": ")" },
{ "open": "'", "close": "'" },
{ "open": "\"", "close": "\"" }
]
}
58 changes: 27 additions & 31 deletions _vscode_plugin/Sillot/src/_sy.language-configuration.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
{
"comments": {
"lineComment": "//",
"blockComment": ["/*", "*/"]
},
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"]
],
"folding": {
"markers": {
"start": "^\\s*//\\s*#?region\\b",
"end": "^\\s*//\\s*#?endregion\\b"
}
},
"autoClosingPairs": [
{ "open": "{", "close": "}" },
{ "open": "[", "close": "]" },
{ "open": "(", "close": ")" },
{ "open": "'", "close": "'", "notIn": ["string", "comment"] },
{ "open": "\"", "close": "\"", "notIn": ["string"] },
{ "open": "`", "close": "`", "notIn": ["string", "comment"] },
{ "open": "/**", "close": " */", "notIn": ["string"] }
],
"surroundingPairs": [
{"open": "{", "close": "}"},
{"open": "[", "close": "]"},
{"open": "(", "close": ")"},
{"open": "'", "close": "'"},
{"open": "\"", "close": "\""}
]
"comments": {
"lineComment": "//",
"blockComment": ["/*", "*/"]
},
"brackets": [["{", "}"], ["[", "]"], ["(", ")"]],
"folding": {
"markers": {
"start": "^\\s*//\\s*#?region\\b",
"end": "^\\s*//\\s*#?endregion\\b"
}
},
"autoClosingPairs": [
{ "open": "{", "close": "}" },
{ "open": "[", "close": "]" },
{ "open": "(", "close": ")" },
{ "open": "'", "close": "'", "notIn": ["string", "comment"] },
{ "open": "\"", "close": "\"", "notIn": ["string"] },
{ "open": "`", "close": "`", "notIn": ["string", "comment"] },
{ "open": "/**", "close": " */", "notIn": ["string"] }
],
"surroundingPairs": [
{ "open": "{", "close": "}" },
{ "open": "[", "close": "]" },
{ "open": "(", "close": ")" },
{ "open": "'", "close": "'" },
{ "open": "\"", "close": "\"" }
]
}
72 changes: 35 additions & 37 deletions _vscode_plugin/Sillot/src/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,62 @@

/** To demonstrate code actions associated with Diagnostics problems, this file provides a mock diagnostics entries. */

import * as vscode from 'vscode';
import * as vscode from "vscode";

/** Code that is used to associate diagnostic entries with code actions. */
export const EMOJI_MENTION = 'emoji_mention';
export const EMOJI_MENTION = "emoji_mention";

/** String to detect in the text document. */
const EMOJI = 'emoji';
const EMOJI = "emoji";

/**
* Analyzes the text document for problems.
* Analyzes the text document for problems.
* This demo diagnostic problem provider finds all mentions of 'emoji'.
* @param doc text document to analyze
* @param emojiDiagnostics diagnostic collection
*/
export function refreshDiagnostics(doc: vscode.TextDocument, emojiDiagnostics: vscode.DiagnosticCollection): void {
const diagnostics: vscode.Diagnostic[] = [];
const diagnostics: vscode.Diagnostic[] = [];

for (let lineIndex = 0; lineIndex < doc.lineCount; lineIndex++) {
const lineOfText = doc.lineAt(lineIndex);
if (lineOfText.text.includes(EMOJI)) {
diagnostics.push(createDiagnostic(doc, lineOfText, lineIndex));
}
}
for (let lineIndex = 0; lineIndex < doc.lineCount; lineIndex++) {
const lineOfText = doc.lineAt(lineIndex);
if (lineOfText.text.includes(EMOJI)) {
diagnostics.push(createDiagnostic(doc, lineOfText, lineIndex));
}
}

emojiDiagnostics.set(doc.uri, diagnostics);
emojiDiagnostics.set(doc.uri, diagnostics);
}

function createDiagnostic(doc: vscode.TextDocument, lineOfText: vscode.TextLine, lineIndex: number): vscode.Diagnostic {
// find where in the line of that the 'emoji' is mentioned
const index = lineOfText.text.indexOf(EMOJI);
// find where in the line of that the 'emoji' is mentioned
const index = lineOfText.text.indexOf(EMOJI);

// create range that represents, where in the document the word is
const range = new vscode.Range(lineIndex, index, lineIndex, index + EMOJI.length);
// create range that represents, where in the document the word is
const range = new vscode.Range(lineIndex, index, lineIndex, index + EMOJI.length);

const diagnostic = new vscode.Diagnostic(range, "When you say 'emoji', do you want to find out more?",
vscode.DiagnosticSeverity.Information);
diagnostic.code = EMOJI_MENTION;
return diagnostic;
const diagnostic = new vscode.Diagnostic(
range,
"When you say 'emoji', do you want to find out more?",
vscode.DiagnosticSeverity.Information
);
diagnostic.code = EMOJI_MENTION;
return diagnostic;
}

export function subscribeToDocumentChanges(context: vscode.ExtensionContext, emojiDiagnostics: vscode.DiagnosticCollection): void {
if (vscode.window.activeTextEditor) {
refreshDiagnostics(vscode.window.activeTextEditor.document, emojiDiagnostics);
}
context.subscriptions.push(
vscode.window.onDidChangeActiveTextEditor(editor => {
if (editor) {
refreshDiagnostics(editor.document, emojiDiagnostics);
}
})
);
if (vscode.window.activeTextEditor) {
refreshDiagnostics(vscode.window.activeTextEditor.document, emojiDiagnostics);
}
context.subscriptions.push(
vscode.window.onDidChangeActiveTextEditor(editor => {
if (editor) {
refreshDiagnostics(editor.document, emojiDiagnostics);
}
})
);

context.subscriptions.push(
vscode.workspace.onDidChangeTextDocument(e => refreshDiagnostics(e.document, emojiDiagnostics))
);

context.subscriptions.push(
vscode.workspace.onDidCloseTextDocument(doc => emojiDiagnostics.delete(doc.uri))
);
context.subscriptions.push(vscode.workspace.onDidChangeTextDocument(e => refreshDiagnostics(e.document, emojiDiagnostics)));

context.subscriptions.push(vscode.workspace.onDidCloseTextDocument(doc => emojiDiagnostics.delete(doc.uri)));
}
21 changes: 10 additions & 11 deletions _vscode_plugin/Sillot/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ export function activate(context: vscode.ExtensionContext) {
Log.d("洛");
Log.a("汐洛", `${Log.Channel.logLevel}`);


// 获取typescript.useCodeSnippetsOnMethodSuggest的值
const test2 = vscode.workspace.getConfiguration("typescript").get("useCodeSnippetsOnMethodSuggest") as string;

Expand Down Expand Up @@ -332,19 +331,19 @@ export function activate(context: vscode.ExtensionContext) {

const codelensProvider = new CodelensProvider();

vscode.languages.registerCodeLensProvider("*", codelensProvider);
vscode.languages.registerCodeLensProvider("*", codelensProvider);

vscode.commands.registerCommand("codelens-sample.enableCodeLens", () => {
vscode.workspace.getConfiguration("codelens-sample").update("enableCodeLens", true, true);
});
vscode.commands.registerCommand("codelens-sample.enableCodeLens", () => {
vscode.workspace.getConfiguration("codelens-sample").update("enableCodeLens", true, true);
});

vscode.commands.registerCommand("codelens-sample.disableCodeLens", () => {
vscode.workspace.getConfiguration("codelens-sample").update("enableCodeLens", false, true);
});
vscode.commands.registerCommand("codelens-sample.disableCodeLens", () => {
vscode.workspace.getConfiguration("codelens-sample").update("enableCodeLens", false, true);
});

vscode.commands.registerCommand("codelens-sample.codelensAction", (args: any) => {
vscode.window.showInformationMessage(`CodeLens action clicked with args=${args}`);
});
vscode.commands.registerCommand("codelens-sample.codelensAction", (args: any) => {
vscode.window.showInformationMessage(`CodeLens action clicked with args=${args}`);
});
}

// 当你的扩展被禁用时,这个方法将被调用
Expand Down
Loading

0 comments on commit 4eec7d4

Please sign in to comment.