From c1895c682dc45a4ab8b84a2f12253245df58aea9 Mon Sep 17 00:00:00 2001 From: Mehmet Bektas Date: Sat, 4 Jan 2025 16:53:03 -0800 Subject: [PATCH] improve login status update --- src/chat-sidebar.tsx | 6 +++--- src/github-copilot.ts | 2 +- src/index.ts | 45 ++----------------------------------------- src/utils.ts | 41 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/chat-sidebar.tsx b/src/chat-sidebar.tsx index a294196..2a61990 100644 --- a/src/chat-sidebar.tsx +++ b/src/chat-sidebar.tsx @@ -329,7 +329,7 @@ function SidebarComponent(props: any) { fetchData(); - const intervalId = setInterval(fetchData, 3000); + const intervalId = setInterval(fetchData, 1000); return () => clearInterval(intervalId); }, [loginClickCount]); @@ -808,7 +808,7 @@ function GitHubCopilotStatusComponent(props: any) { fetchData(); - const intervalId = setInterval(fetchData, 3000); + const intervalId = setInterval(fetchData, 1000); return () => clearInterval(intervalId); }, [loginClickCount]); @@ -842,7 +842,7 @@ function GitHubCopilotLoginDialogBodyComponent(props: any) { fetchData(); - const intervalId = setInterval(fetchData, 3000); + const intervalId = setInterval(fetchData, 1000); return () => clearInterval(intervalId); }, [loginClickCount]); diff --git a/src/github-copilot.ts b/src/github-copilot.ts index 9c80b65..4a4b248 100644 --- a/src/github-copilot.ts +++ b/src/github-copilot.ts @@ -7,7 +7,7 @@ import { UUID } from '@lumino/coreutils'; import { Signal } from '@lumino/signaling'; import { IChatCompletionResponseEmitter, RequestDataType } from "./tokens"; -const LOGIN_STATUS_UPDATE_INTERVAL = 3000; +const LOGIN_STATUS_UPDATE_INTERVAL = 2000; export enum GitHubCopilotLoginStatus { NotLoggedIn = 'NOT_LOGGED_IN', diff --git a/src/index.ts b/src/index.ts index f040d9b..029ed11 100644 --- a/src/index.ts +++ b/src/index.ts @@ -49,7 +49,7 @@ import { ChatSidebar, GitHubCopilotLoginDialogBody, GitHubCopilotStatusBarItem, import { GitHubCopilot } from './github-copilot'; import { IActiveDocumentInfo } from './tokens'; import sparklesSvgstr from '../style/icons/sparkles.svg'; -import { removeAnsiChars, waitForDuration } from './utils'; +import { extractCodeFromMarkdown, removeAnsiChars, waitForDuration } from './utils'; namespace CommandIDs { export const chatuserInput = 'notebook-intelligence:chat_user_input'; @@ -253,7 +253,7 @@ const plugin: JupyterFrontEndPlugin = { execute: async (args) => { const contents = new ContentsManager(); const newPyFile = await contents.newUntitled({ext: '.py', path: defaultBrowser?.model.path}); - contents.save(newPyFile.path, { content: args.code, format: 'text', type: 'file' }); + contents.save(newPyFile.path, { content: extractCodeFromMarkdown(args.code as string), format: 'text', type: 'file' }); docManager.openOrReveal(newPyFile.path); await waitForFileToBeActive(newPyFile.path); @@ -437,47 +437,6 @@ const plugin: JupyterFrontEndPlugin = { return newLines.join('\n'); }; - const moveCodeSectionBoundaryMarkersToNewLine = (source: string): string => { - const existingLines = source.split('\n'); - const newLines = []; - for (const line of existingLines) { - if (line.length > 3 && line.startsWith('```')) { - newLines.push('```'); - let remaining = line.substring(3); - if (remaining.startsWith('python')) { - if (remaining.length === 6) { - continue; - } - remaining = remaining.substring(6); - } - if (remaining.endsWith('```')) { - newLines.push(remaining.substring(0, remaining.length - 3)); - newLines.push('```'); - } else { - newLines.push(remaining); - } - } else if (line.length > 3 && line.endsWith('```')) { - newLines.push(line.substring(0, line.length - 3)); - newLines.push('```'); - } else { - newLines.push(line); - } - } - return newLines.join('\n'); - }; - - const extractCodeFromMarkdown = (source: string): string => { - // make sure end of code block is in new line - source = moveCodeSectionBoundaryMarkersToNewLine(source); - const codeBlockRegex = /^```(?:\w+)?\s*\n(.*?)(?=^```)```/gms; - let code = ''; - let match; - while ((match = codeBlockRegex.exec(source)) !== null) { - code += match[1] + '\n'; - } - return code.trim() || source; - }; - const {prefix, suffix} = getPrefixAndSuffixForActiveCell(); const inlinePrompt = new InlinePromptWidget(rect, { diff --git a/src/utils.ts b/src/utils.ts index af349cf..da987ef 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -14,3 +14,44 @@ export async function waitForDuration(duration: number): Promise { }, duration); }); } + +export function moveCodeSectionBoundaryMarkersToNewLine(source: string): string { + const existingLines = source.split('\n'); + const newLines = []; + for (const line of existingLines) { + if (line.length > 3 && line.startsWith('```')) { + newLines.push('```'); + let remaining = line.substring(3); + if (remaining.startsWith('python')) { + if (remaining.length === 6) { + continue; + } + remaining = remaining.substring(6); + } + if (remaining.endsWith('```')) { + newLines.push(remaining.substring(0, remaining.length - 3)); + newLines.push('```'); + } else { + newLines.push(remaining); + } + } else if (line.length > 3 && line.endsWith('```')) { + newLines.push(line.substring(0, line.length - 3)); + newLines.push('```'); + } else { + newLines.push(line); + } + } + return newLines.join('\n'); +} + +export function extractCodeFromMarkdown(source: string): string { + // make sure end of code block is in new line + source = moveCodeSectionBoundaryMarkersToNewLine(source); + const codeBlockRegex = /^```(?:\w+)?\s*\n(.*?)(?=^```)```/gms; + let code = ''; + let match; + while ((match = codeBlockRegex.exec(source)) !== null) { + code += match[1] + '\n'; + } + return code.trim() || source; +}