import * as vscode from "vscode" ; export class CustomCodeLensProvider implements vscode . CodeLensProvider { private onDidChangeCodeLensesEmitter : vscode . EventEmitter < void > = new vscode . EventEmitter < void > ( ) ; get onDidChangeCodeLenses ( ) : vscode . Event < void > { return this . onDidChangeCodeLensesEmitter . event ; } public refresh ( ) { this . onDidChangeCodeLensesEmitter . fire ( ) ; } public provideCodeLenses ( document ) { const content = document . getText ( ) ; let ext ; if ( document . fileName . endsWith ( ".md" ) ) { ext = "md" ; } if ( document . fileName . endsWith ( ".js" ) ) { ext = "js" ; } let codeLensLine = document . lineCount - 1 ; for ( let i = document . lineCount - 1 ; i >= 0 ; i -- ) { const lineContent = document . lineAt ( i ) . text ; if ( ext === "md" && lineContent . indexOf ( "*[interview]: end" ) >= 0 ) { codeLensLine = i ; break ; } if ( ext === "js" && lineContent . indexOf ( "// @interview end" ) >= 0 ) { codeLensLine = i ; break ; } } if ( ext === void 0 ) { return [ ] ; } if ( ( content . indexOf ( "*[interview]: start" ) < 0 || content . indexOf ( "*[interview]: end" ) < 0 ) && ext === "md" ) { return [ ] ; } if ( ( content . indexOf ( "// @interview start" ) < 0 || content . indexOf ( "// @interview end" ) < 0 ) && ext === "js" ) { return [ ] ; } const range = new vscode . Range ( codeLensLine , 0 , codeLensLine , 0 ) ; const codeLens = [ ] ; codeLens . push ( new vscode . CodeLens ( range , { title : "☑️提交答案" , command : "interview.postAnswer" , arguments : [ document , content ] , } ) ) ; codeLens . push ( new vscode . CodeLens ( range , { title : "👀查看题解" , command : "interview.openAnswer" , arguments : [ document ] , } ) ) ; codeLens . push ( new vscode . CodeLens ( range , { title : "🐦保存到语雀" , command : "zffe.YQsave" , arguments : [ document , content ] , } ) ) ; codeLens . push ( new vscode . CodeLens ( range , { title : "👍分享题目" , command : "interview.sharePoster" , arguments : [ content ] , } ) ) ; return codeLens ; } } export const customCodeLensProvider = new CustomCodeLensProvider ( ) ;