File tree Expand file tree Collapse file tree 3 files changed +59
-0
lines changed
Expand file tree Collapse file tree 3 files changed +59
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 1+ import { MarkdownHTTPCodeLensProvider } from "./base" ;
2+
3+ export const httpRepeater = new MarkdownHTTPCodeLensProvider ( ) ;
Original file line number Diff line number Diff line change 1+ import { MarkdownHTTPCodeLensGenerator } from "./base" ;
2+
3+
You can’t perform that action at this time.
0 commit comments