Skip to content

Commit

Permalink
fix: Properly type the renderer and remove @ts-ignore in renderChatLog
Browse files Browse the repository at this point in the history
- Used Partial<Renderer> to create a partial implementation of the Renderer interface.
- Removed @ts-ignore directive and fixed type definitions for the renderer.
- Ensured type safety and maintained code quality.
  • Loading branch information
wyennie committed Sep 24, 2024
1 parent ae5636e commit e58f7e0
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/views/chatView/chatRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// permissions and limitations under the License.
import * as vscode from 'vscode';
import * as fs from 'fs';
import { marked } from 'marked';
import { marked, Renderer, Tokens } from 'marked';
import { ChatMessage, TreeItem } from '../../types/ChatTypes';
import { getTreeData } from './utils/PipelineUtils';

Expand Down Expand Up @@ -76,16 +76,14 @@ export function renderChatLog(
messages: ChatMessage[],
streamingMessage: ChatMessage | null = null
): string {
const renderer = {
// @ts-ignore
code({ text, lang, escaped, isInline }) {
const code = text.replace(/\n$/, '') + (isInline ? '' : '\n');
return isInline ? `<code>${code}</code>` : '<pre><code>' + code + '</code></pre>\n';
const renderer: Partial<Renderer> = {
code({ text, lang, escaped }: Tokens.Code) {
const formattedCode = text.replace(/\n$/, '') + (escaped ? '' : '\n');
return escaped ? `<code>${formattedCode}</code>` : '<pre><code>' + formattedCode + '</code></pre>\n';
},
};

// @ts-ignore
marked.use({ renderer });
marked.use({ renderer: renderer as Renderer });

const renderedMessages = messages
.filter(msg => msg['role'] !== 'system')
Expand Down

0 comments on commit e58f7e0

Please sign in to comment.