@@ -21,6 +21,7 @@ import { attachRouterToPanel } from "@webview-rpc/host";
2121import { createLogger } from "./utils/logger.js" ;
2222import { checkForUpdates } from "./utils/checkForUpdates.js" ;
2323import { reverseApplyDiff } from "./utils/diff-utils.js" ;
24+ import type MarkdownIt from "markdown-it" ;
2425
2526const DEFAULT_MODEL = "deepseek-v4-pro" ;
2627const DEFAULT_BASE_URL = "https://api.deepseek.com" ;
@@ -252,9 +253,7 @@ export class DeepCodeViewProvider implements vscode.WebviewViewProvider {
252253 }
253254
254255 private getWorkspaceRoot ( ) : string {
255- const workspace = vscode . workspace . workspaceFolders ?. [ 0 ] ;
256- if ( workspace ) return workspace . uri . fsPath ;
257- return process . cwd ( ) ;
256+ return getWorkspaceRootFn ( ) ;
258257 }
259258
260259 private createOpenAIClient ( ) : {
@@ -316,16 +315,7 @@ export class DeepCodeViewProvider implements vscode.WebviewViewProvider {
316315 }
317316
318317 private async openFileInEditor ( filePath : string , line : number ) : Promise < void > {
319- const document = await vscode . workspace . openTextDocument ( vscode . Uri . file ( filePath ) ) ;
320- const editor = await vscode . window . showTextDocument ( document , {
321- preview : false ,
322- preserveFocus : false ,
323- } ) ;
324- const targetLine = Number . isFinite ( line ) && line > 0 ? Math . floor ( line ) - 1 : 0 ;
325- const safeLine = Math . min ( Math . max ( 0 , targetLine ) , Math . max ( 0 , document . lineCount - 1 ) ) ;
326- const position = new vscode . Position ( safeLine , 0 ) ;
327- editor . selection = new vscode . Selection ( position , position ) ;
328- editor . revealRange ( new vscode . Range ( position , position ) , vscode . TextEditorRevealType . InCenter ) ;
318+ return openFileInEditorFn ( filePath , line ) ;
329319 }
330320
331321 /**
@@ -384,7 +374,28 @@ export class DeepCodeViewProvider implements vscode.WebviewViewProvider {
384374 }
385375}
386376
387- export async function activate ( context : vscode . ExtensionContext ) : Promise < void > {
377+ async function openFileInEditorFn ( filePath : string , line : number ) : Promise < void > {
378+ const document = await vscode . workspace . openTextDocument ( vscode . Uri . file ( filePath ) ) ;
379+ const editor = await vscode . window . showTextDocument ( document , {
380+ preview : false ,
381+ preserveFocus : false ,
382+ } ) ;
383+ const targetLine = Number . isFinite ( line ) && line > 0 ? Math . floor ( line ) - 1 : 0 ;
384+ const safeLine = Math . min ( Math . max ( 0 , targetLine ) , Math . max ( 0 , document . lineCount - 1 ) ) ;
385+ const position = new vscode . Position ( safeLine , 0 ) ;
386+ editor . selection = new vscode . Selection ( position , position ) ;
387+ editor . revealRange ( new vscode . Range ( position , position ) , vscode . TextEditorRevealType . InCenter ) ;
388+ }
389+
390+ function getWorkspaceRootFn ( ) : string {
391+ const workspace = vscode . workspace . workspaceFolders ?. [ 0 ] ;
392+ if ( workspace ) return workspace . uri . fsPath ;
393+ return process . cwd ( ) ;
394+ }
395+
396+ export async function activate (
397+ context : vscode . ExtensionContext
398+ ) : Promise < { extendMarkdownIt ( md : MarkdownIt ) : MarkdownIt } > {
388399 process . env . NoDefaultCurrentDirectoryInExePath = "1" ;
389400 logger = vscode . window . createOutputChannel ( "Deep Code" ) ;
390401 log = createLogger ( context , logger ) ;
@@ -438,13 +449,57 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
438449 } )
439450 ) ;
440451
452+ // Open view
441453 context . subscriptions . push (
442454 vscode . commands . registerCommand ( "deepcode.openView" , async ( ) => {
443455 await vscode . commands . executeCommand ( "workbench.view.extension.deepcode" ) ;
444456 await vscode . commands . executeCommand ( "deepcode.chatView.focus" ) ;
445457 } )
446458 ) ;
459+ // Open settings
460+ context . subscriptions . push (
461+ vscode . commands . registerCommand ( "deepcode.settings" , async ( ) => {
462+ const projectRoot = getWorkspaceRootFn ( ) ;
463+ const projectSettingsPath = path . join ( projectRoot , ".deepcode" , "settings.json" ) ;
464+ const userSettingsPath = path . join ( os . homedir ( ) , ".deepcode" , "settings.json" ) ;
465+
466+ if ( fs . existsSync ( projectSettingsPath ) ) {
467+ await openFileInEditorFn ( projectSettingsPath , 1 ) ;
468+ } else {
469+ // Ensure user settings directory exists
470+ const userSettingsDir = path . dirname ( userSettingsPath ) ;
471+ if ( ! fs . existsSync ( userSettingsDir ) ) {
472+ fs . mkdirSync ( userSettingsDir , { recursive : true } ) ;
473+ }
474+ if ( ! fs . existsSync ( userSettingsPath ) ) {
475+ fs . writeFileSync ( userSettingsPath , JSON . stringify ( { } , null , 2 ) , "utf8" ) ;
476+ }
477+ await openFileInEditorFn ( userSettingsPath , 1 ) ;
478+ }
479+ } )
480+ ) ;
481+
482+ // Create new chat
483+ context . subscriptions . push (
484+ vscode . commands . registerCommand ( "deepcode.newchat" , ( ) => {
485+ log ( "deepcode.newchat" ) ;
486+ provider . postMessageToWebview ( { type : "triggerNewChat" } ) ;
487+ } )
488+ ) ;
489+
490+ // Show history
491+ context . subscriptions . push (
492+ vscode . commands . registerCommand ( "deepcode.history" , ( ) => {
493+ log ( "deepcode.history" ) ;
494+ provider . postMessageToWebview ( { type : "triggerHistory" } ) ;
495+ } )
496+ ) ;
447497 context . subscriptions . push ( logger ) ;
498+ return {
499+ extendMarkdownIt ( md : MarkdownIt ) {
500+ return md . use ( require ( "markdown-it-task-lists" ) ) ;
501+ } ,
502+ } ;
448503}
449504
450505export function deactivate ( ) : void {
0 commit comments