Skip to content

Commit 8950354

Browse files
committed
update: repeater startup
1 parent c1d5cd2 commit 8950354

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

src/codelens/httpreapter/base.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import * as vscode from "vscode";
2+
import { logger } from "../../global/log";
3+
4+
export type MarkdownHTTPCodeLensGenerator = (
5+
post: string,
6+
startLine: number,
7+
document: vscode.TextDocument
8+
) => vscode.CodeLens[];
9+
10+
export class MarkdownHTTPCodeLensProvider implements vscode.CodeLensProvider {
11+
private generators: MarkdownHTTPCodeLensGenerator[];
12+
constructor(...generators: MarkdownHTTPCodeLensGenerator[]) {
13+
this.generators = generators;
14+
}
15+
16+
provideCodeLenses(
17+
document: vscode.TextDocument,
18+
token: vscode.CancellationToken
19+
): vscode.ProviderResult<vscode.CodeLens[]> {
20+
const codeLenses: vscode.CodeLens[] = [];
21+
const lines = document.getText().split("\n");
22+
23+
let inYaml = false;
24+
let currentPost = "";
25+
let yamlStartLine = 0;
26+
27+
for (let i = 0; i < lines.length; i++) {
28+
const line = lines[i];
29+
if (inYaml) {
30+
if (line === "```") {
31+
for (const generator of this.generators) {
32+
try {
33+
codeLenses.push(
34+
...generator(currentPost, yamlStartLine, document)
35+
);
36+
} catch (error) {
37+
logger.error("Error generating code lenses: ", error);
38+
}
39+
}
40+
inYaml = false;
41+
currentPost = "";
42+
} else {
43+
currentPost += line + "\n";
44+
}
45+
} else if (line.startsWith("```http")) {
46+
inYaml = true;
47+
yamlStartLine = i;
48+
}
49+
}
50+
51+
return codeLenses;
52+
}
53+
}

src/codelens/httpreapter/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { MarkdownHTTPCodeLensProvider } from "./base";
2+
3+
export const httpRepeater = new MarkdownHTTPCodeLensProvider();

src/codelens/httpreapter/send.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { MarkdownHTTPCodeLensGenerator } from "./base";
2+
3+

0 commit comments

Comments
 (0)