Skip to content

Commit 04bbccb

Browse files
committed
Update VS Code engine to 1.96, implement commit message token limits, and enhance panel UI elements
- code blocks on rendered website don't have syntax highlighting <pre><code class="language-cs">AudioClip speech = await "Welcome back, Commander!" .GENSpeech() .SetVoice(ElevenLabsVoice.Rachel) .ExecuteAsync(); </code></pre> - can the [Fragment] use different icon? e.g. globe - instead of [Fragment] show the domain of the url, e.g. github.com - for settings use iconPath 'gear' - when a file has more tokens than 20K - don't attach its full contents in the commit message and don't list token count on the 'unstaged files' quick pick - move the 20k token limit to a const
1 parent 2c1f2c7 commit 04bbccb

7 files changed

Lines changed: 50 additions & 14 deletions

File tree

‎apps/editor/package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"url": "https://github.com/robertpiosik/CodeWebChat"
2222
},
2323
"engines": {
24-
"vscode": "^1.92.0"
24+
"vscode": "^1.96.0"
2525
},
2626
"sponsor": {
2727
"url": "https://github.com/sponsors/robertpiosik"
@@ -1978,7 +1978,7 @@
19781978
"@types/node": "20.x",
19791979
"@types/react": "^18.2.60",
19801980
"@types/react-dom": "^18.2.19",
1981-
"@types/vscode": "1.92.0",
1981+
"@types/vscode": "1.96.0",
19821982
"@types/ws": "^8.18.1",
19831983
"@types/turndown": "^5.0.5",
19841984
"@typescript-eslint/eslint-plugin": "^7.18.0",

‎apps/editor/src/commands/generate-commit-message-command/utils/build-commit-message-prompt.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as vscode from 'vscode'
22
import { commit_message_instructions } from '@/constants/instructions'
33
import type { GitRepository } from '@/utils/git-repository-utils'
4+
import { MAX_FILE_TOKENS_FOR_COMMIT_MESSAGE } from '@/constants/values'
45

56
export const build_commit_message_prompt = async (
67
diff: string,
@@ -99,7 +100,10 @@ export const build_commit_message_prompt = async (
99100
full_content = Buffer.from(content).toString('utf8')
100101
}
101102
if (full_content) {
102-
changes_content += `<![CDATA[\n${full_content.trimEnd()}\n]]>\n`
103+
const full_content_tokens = Math.ceil(full_content.length / 4)
104+
if (full_content_tokens <= MAX_FILE_TOKENS_FOR_COMMIT_MESSAGE) {
105+
changes_content += `<![CDATA[\n${full_content.trimEnd()}\n]]>\n`
106+
}
103107
}
104108
} catch (err) {}
105109
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export const CHECKPOINT_DEFAULT_LIFESPAN = 24
22
export const DEFAULT_CONTEXT_SIZE_WARNING_THRESHOLD = 60000
3+
export const MAX_FILE_TOKENS_FOR_COMMIT_MESSAGE = 20000

‎apps/editor/src/utils/git-repository-utils.ts‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { dictionary } from '@shared/constants/dictionary'
44
import * as path from 'path'
55
import { t } from '@/i18n'
66
import { display_token_count } from './display-token-count'
7+
import { MAX_FILE_TOKENS_FOR_COMMIT_MESSAGE } from '@/constants/values'
78

89
export type GitRepository = {
910
rootUri: vscode.Uri
@@ -166,18 +167,26 @@ export const prepare_staged_changes = async (
166167
}
167168
} catch (e) {}
168169

170+
const file_tokens = Math.ceil(
171+
(full_content ? full_content.length : final_diff_content.length) / 4
172+
)
173+
const is_too_large = file_tokens > MAX_FILE_TOKENS_FOR_COMMIT_MESSAGE
174+
169175
let file_xml = `<file path="${relative_path}" status="${status}">\n`
170176
file_xml += `<![CDATA[\n${final_diff_content.trimEnd()}\n]]>\n`
171-
if (!is_deleted && full_content) {
177+
if (!is_deleted && full_content && !is_too_large) {
172178
file_xml += `<![CDATA[\n${full_content.trimEnd()}\n]]>\n`
173179
}
174180
file_xml += `</file>\n`
175181

176182
const token_count = Math.ceil(file_xml.length / 4)
177-
const tokens_str = display_token_count(token_count)
178183
const description_parts = []
179-
description_parts.push(tokens_str)
180-
if (dir_name !== '.') description_parts.push(dir_name)
184+
185+
if (!is_too_large) {
186+
const tokens_str = display_token_count(token_count)
187+
description_parts.push(tokens_str)
188+
}
189+
if (dir_name != '.') description_parts.push(dir_name)
181190

182191
return {
183192
label: path.basename(relative_path),

‎apps/editor/src/views/panel/backend/message-handlers/handle-open-website.ts‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@ export const handle_open_website = async (message: OpenWebsiteMessage) => {
1515
const markdown = fs.readFileSync(file_path, 'utf8')
1616
const html = await marked.parse(markdown)
1717

18+
const title = new URL(message.url).hostname
19+
1820
const panel = vscode.window.createWebviewPanel(
1921
'websitePreview',
20-
'Website Preview',
21-
vscode.ViewColumn.One
22+
title,
23+
vscode.ViewColumn.One,
24+
{ enableScripts: true }
2225
)
2326

27+
panel.iconPath = new vscode.ThemeIcon('globe') as any
28+
2429
current_preview_url = message.url
2530
vscode.commands.executeCommand(
2631
'setContext',
@@ -56,18 +61,33 @@ export const handle_open_website = async (message: OpenWebsiteMessage) => {
5661
}
5762
})
5863

64+
const csp = panel.webview.cspSource
65+
5966
panel.webview.html = `
6067
<!DOCTYPE html>
6168
<html lang="en">
6269
<head>
6370
<meta charset="UTF-8">
71+
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src ${csp} 'unsafe-inline' https://cdnjs.cloudflare.com; script-src 'unsafe-inline' https://cdnjs.cloudflare.com; font-src https://cdnjs.cloudflare.com;">
6472
<meta name="viewport" content="width=device-width, initial-scale=1.0">
73+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/styles/vs2015.min.css">
74+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/highlight.min.js"></script>
75+
<script>document.addEventListener('DOMContentLoaded', () => hljs.highlightAll());</script>
6576
<title>${message.url}</title>
6677
<style>
6778
body {
6879
line-height: 1.5;
6980
padding: 20px 40px;
7081
}
82+
pre code.hljs {
83+
border-radius: 6px;
84+
padding: 10px 12px;
85+
border: 1px solid color-mix(in srgb, var(--vscode-foreground) 25%, transparent);
86+
}
87+
pre {
88+
margin: 16px 0;
89+
font-size: 12px;
90+
}
7191
</style>
7292
</head>
7393
<body>

‎apps/editor/src/views/settings/backend/settings-provider.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ export class SettingsProvider {
8787
}
8888
)
8989

90+
this._webview_panel.iconPath = new vscode.ThemeIcon('gear') as any
91+
9092
this._webview_panel.onDidDispose(() => {
9193
this._webview_panel = undefined
9294
this._disposables.forEach((d) => d.dispose())

‎pnpm-lock.yaml‎

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)