Skip to content

Commit

Permalink
improve login status update
Browse files Browse the repository at this point in the history
  • Loading branch information
mbektas committed Jan 5, 2025
1 parent fad888a commit c1895c6
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 47 deletions.
6 changes: 3 additions & 3 deletions src/chat-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ function SidebarComponent(props: any) {

fetchData();

const intervalId = setInterval(fetchData, 3000);
const intervalId = setInterval(fetchData, 1000);

return () => clearInterval(intervalId);
}, [loginClickCount]);
Expand Down Expand Up @@ -808,7 +808,7 @@ function GitHubCopilotStatusComponent(props: any) {

fetchData();

const intervalId = setInterval(fetchData, 3000);
const intervalId = setInterval(fetchData, 1000);

return () => clearInterval(intervalId);
}, [loginClickCount]);
Expand Down Expand Up @@ -842,7 +842,7 @@ function GitHubCopilotLoginDialogBodyComponent(props: any) {

fetchData();

const intervalId = setInterval(fetchData, 3000);
const intervalId = setInterval(fetchData, 1000);

return () => clearInterval(intervalId);
}, [loginClickCount]);
Expand Down
2 changes: 1 addition & 1 deletion src/github-copilot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
45 changes: 2 additions & 43 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -253,7 +253,7 @@ const plugin: JupyterFrontEndPlugin<void> = {
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);
Expand Down Expand Up @@ -437,47 +437,6 @@ const plugin: JupyterFrontEndPlugin<void> = {
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, {
Expand Down
41 changes: 41 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,44 @@ export async function waitForDuration(duration: number): Promise<void> {
}, 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;
}

0 comments on commit c1895c6

Please sign in to comment.