Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ jobs:
with:
extra_args: --all-files
- run: npm install
- run: npm run prettier:check
- run: npm run build
6 changes: 6 additions & 0 deletions exa/codeium_common_pb/codeium_common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ message Metadata {
}];
}

// Next ID: 3, Previous field: insert_spaces.
message EditorOptions {
uint64 tab_size = 1 [(validate.rules).uint64.gt = 0];
bool insert_spaces = 2;
}

message Event {
EventType event_type = 1;
string event_json = 2;
Expand Down
8 changes: 1 addition & 7 deletions exa/language_server_pb/language_server.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ service LanguageServerService {
message GetCompletionsRequest {
codeium_common_pb.Metadata metadata = 1 [(validate.rules).message.required = true];
Document document = 2 [(validate.rules).message.required = true];
EditorOptions editor_options = 3 [(validate.rules).message.required = true];
codeium_common_pb.EditorOptions editor_options = 3 [(validate.rules).message.required = true];
repeated Document other_documents = 5;
}

Expand Down Expand Up @@ -82,12 +82,6 @@ message Document {
}];
}

// Next ID: 3, Previous field: insert_spaces.
message EditorOptions {
uint64 tab_size = 1 [(validate.rules).uint64.gt = 0];
bool insert_spaces = 2;
}

enum CodeiumState {
CODEIUM_STATE_UNSPECIFIED = 0;
CODEIUM_STATE_INACTIVE = 1;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "chrome-extension-webpack",
"version": "1.2.11",
"version": "1.2.15",
"description": "Get started with Chrome extensions development using webpack, Typescript, Sass, and more",
"scripts": {
"generate": "rm -rf ./proto && node generate.js",
"start": "npm run generate && webpack --watch --config webpack.dev.js",
"build": "npm run lint && webpack --config webpack.prod.js && cd dist && zip -r ../dist.zip .",
"lint": "npm run generate && tsc --noEmit && eslint --ext .ts --max-warnings=0 .",
"lint": "npm run generate && tsc --noEmit && eslint --ext .ts,.tsx --max-warnings=0 .",
"prettier": "prettier --write .",
"prettier:check": "prettier --check .",
"postinstall": "patch-package"
Expand Down Expand Up @@ -81,8 +81,5 @@
"npm run prettier",
"npm run lint"
]
},
"main": "generate.js",
"keywords": [],
"author": ""
}
}
2 changes: 1 addition & 1 deletion src/codemirror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { editorLanguage, language } from './codemirrorLanguages';
import { CODEIUM_DEBUG, IdeInfo, LanguageServerClient } from './common';
import { TextAndOffsets, computeTextAndOffsets } from './notebook';
import { numUtf8BytesToNumCodeUnits } from './utf';
import { EditorOptions } from '../proto/exa/codeium_common_pb/codeium_common_pb';
import {
CompletionItem,
CompletionPartType,
EditorOptions,
GetCompletionsRequest,
} from '../proto/exa/language_server_pb/language_server_pb';

Expand Down
2 changes: 1 addition & 1 deletion src/codemirrorInject.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CodeMirrorManager } from './codemirror';
import { EditorOptions } from '../proto/exa/language_server_pb/language_server_pb';
import { EditorOptions } from '../proto/exa/codeium_common_pb/codeium_common_pb';

declare type CodeMirror = typeof import('codemirror');

Expand Down
2 changes: 1 addition & 1 deletion src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '../proto/exa/language_server_pb/language_server_pb';

const EXTENSION_NAME = 'chrome';
const EXTENSION_VERSION = '1.2.11';
const EXTENSION_VERSION = '1.2.15';
const BASE_URL = 'https://server.codeium.com';

export const CODEIUM_DEBUG = false;
Expand Down
31 changes: 17 additions & 14 deletions src/component/Options.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import React, { createRef, useEffect, useState } from 'react';

import { PROFILE_URL } from '../auth';
import { getStorageItem, setStorageItem, defaultAllowList } from '../storage';
import Box from '@mui/material/Box';
import { TextField, Button, Link, Typography, Snackbar, Alert } from '@mui/material';
import SettingsIcon from '@mui/icons-material/Settings';
import OpenInNewIcon from '@mui/icons-material/OpenInNew';
import LoginIcon from '@mui/icons-material/Login';
import SaveAltIcon from '@mui/icons-material/SaveAlt';
import OpenInNewIcon from '@mui/icons-material/OpenInNew';
import RestartAltIcon from '@mui/icons-material/RestartAlt';
import SaveAltIcon from '@mui/icons-material/SaveAlt';
import SettingsIcon from '@mui/icons-material/Settings';
import { Alert, Button, Link, Snackbar, TextField, Typography } from '@mui/material';
import Box from '@mui/material/Box';
import Divider from '@mui/material/Divider';
import React, { createRef, useEffect, useState } from 'react';
import { v4 as uuidv4 } from 'uuid';

import { PROFILE_URL } from '../auth';
import { computeAllowlist, defaultAllowlist, getStorageItem, setStorageItem } from '../storage';

const EditableList = () => {
const [text, setText] = useState('');
const [open, setOpen] = useState(false);
Expand All @@ -20,8 +20,8 @@ const EditableList = () => {

useEffect(() => {
(async () => {
const allowList = (await getStorageItem('allowList')) ?? [];
setText(allowList.join('\n'));
const allowlist = computeAllowlist(await getStorageItem('allowlist'));
setText(allowlist.join('\n'));
})();
}, []);

Expand Down Expand Up @@ -64,7 +64,7 @@ const EditableList = () => {
return;
}
}
setStorageItem('allowList', lst);
setStorageItem('allowlist', { defaults: defaultAllowlist, current: lst });
setSeverity('success');
setMessage('Saved successfully');
setOpen(true);
Expand All @@ -86,8 +86,11 @@ const EditableList = () => {
}}
onClick={async () => {
try {
await setStorageItem('allowList', defaultAllowList);
setText(defaultAllowList.join('\n'));
await setStorageItem('allowlist', {
defaults: defaultAllowlist,
current: defaultAllowlist,
});
setText(defaultAllowlist.join('\n'));
setSeverity('success');
setMessage('Reset successfully');
setOpen(true);
Expand Down
2 changes: 1 addition & 1 deletion src/jupyterInject.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type CodeMirror from 'codemirror';

import { CodeMirrorManager } from './codemirror';
import { EditorOptions } from '../proto/exa/language_server_pb/language_server_pb';
import { EditorOptions } from '../proto/exa/codeium_common_pb/codeium_common_pb';

declare class Cell {
code_mirror: CodeMirror.Editor;
Expand Down
2 changes: 1 addition & 1 deletion src/jupyterlabPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { type Widget } from '@lumino/widgets';
import type CodeMirror from 'codemirror';

import { CodeMirrorManager, addListeners } from './codemirror';
import { EditorOptions } from '../proto/exa/language_server_pb/language_server_pb';
import { EditorOptions } from '../proto/exa/codeium_common_pb/codeium_common_pb';

const COMMAND_ACCEPT = 'codeium:accept-completion';
const COMMAND_DISMISS = 'codeium:dismiss-completion';
Expand Down
1 change: 1 addition & 0 deletions src/options.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import '../styles/options.scss';
import React from 'react';
import ReactDOM from 'react-dom';

import Options from './component/Options';

const container = document.getElementById('codeium-options');
Expand Down
17 changes: 9 additions & 8 deletions src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,25 @@ import { CodeMirrorState } from './codemirrorInject';
import { inject as jupyterInject } from './jupyterInject';
import { getPlugin } from './jupyterlabPlugin';
import { MonacoCompletionProvider, MonacoSite, OMonacoSite } from './monacoCompletionProvider';
import { Storage, computeAllowlist } from './storage';

declare type Monaco = typeof import('monaco-editor');
declare type CodeMirror = typeof import('codemirror');

const params = new URLSearchParams((document.currentScript as HTMLScriptElement).src.split('?')[1]);
const extensionId = params.get('id')!;

async function getAllowList(extensionId: string): Promise<string[] | undefined> {
const allowList = await new Promise<Storage['allowList']>((resolve) => {
async function getAllowlist(extensionId: string): Promise<Storage['allowlist'] | undefined> {
const allowlist = await new Promise<Storage['allowlist']>((resolve) => {
chrome.runtime.sendMessage(
extensionId,
{ type: 'allowList' },
(response: Storage['allowList']) => {
{ type: 'allowlist' },
(response: Storage['allowlist']) => {
resolve(response);
}
);
});
return allowList;
return allowlist;
}

// Clear any bad state from another tab.
Expand Down Expand Up @@ -211,11 +212,11 @@ const addCodeMirror5LocalInject = () => {
}, 100);
};

getAllowList(extensionId).then((allowList) => {
for (const addr of allowList ?? []) {
getAllowlist(extensionId).then((allowlist) => {
for (const addr of computeAllowlist(allowlist)) {
const host = new RegExp(addr);
if (host.test(window.location.href)) {
// the url matches the allowList
// the url matches the allowlist
addMonacoInject();
addCodeMirror5GlobalInject();
addCodeMirror5LocalInject();
Expand Down
10 changes: 5 additions & 5 deletions src/serviceWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from './common';
import { loggedIn, loggedOut, unhealthy } from './shared';
import {
defaultAllowList,
defaultAllowlist,
getStorageItem,
initializeStorageWithDefaults,
setStorageItem,
Expand All @@ -25,7 +25,7 @@ chrome.runtime.onInstalled.addListener(async () => {

await initializeStorageWithDefaults({
settings: {},
allowList: defaultAllowList,
allowlist: { defaults: defaultAllowlist, current: defaultAllowlist },
});

console.log('Extension successfully installed!');
Expand Down Expand Up @@ -57,9 +57,9 @@ chrome.runtime.onMessageExternal.addListener(async (message, sender, sendRespons
}
return;
}
if (message.type === 'allowList') {
const allowList = await getStorageItem('allowList');
sendResponse(allowList);
if (message.type === 'allowlist') {
const allowlist = await getStorageItem('allowlist');
sendResponse(allowlist);
return;
}
if (message.type == 'error') {
Expand Down
37 changes: 35 additions & 2 deletions src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,40 @@ export interface Storage {
message?: string;
};
// regexes of domains to watch
allowList: string[];
allowlist?: {
// Defaults at the time of saving the setting.
defaults: string[];
current: string[];
};
}

// In case the defaults change over time, reconcile the saved setting with the
// new default allowlist.
export function computeAllowlist(
allowlist:
| {
defaults: string[];
current: string[];
}
| undefined
): string[] {
if (allowlist === undefined) {
allowlist = {
defaults: [],
current: [],
};
}
for (const newDefault of defaultAllowlist) {
if (!allowlist.defaults.includes(newDefault) && !allowlist.current.includes(newDefault)) {
allowlist.current.push(newDefault);
}
}
for (const oldDefault of allowlist.defaults) {
if (!defaultAllowlist.includes(oldDefault) && allowlist.current.includes(oldDefault)) {
allowlist.current.splice(allowlist.current.indexOf(oldDefault), 1);
}
}
return allowlist.current;
}

export function getStorageData(): Promise<Storage> {
Expand Down Expand Up @@ -70,7 +103,7 @@ export async function initializeStorageWithDefaults(defaults: Storage) {
}

// default allowlist
export const defaultAllowList = [
export const defaultAllowlist = [
/https:\/\/colab.research\.google\.com\/.*/,
/https:\/\/(.*\.)?stackblitz\.com\/.*/,
/https:\/\/(.*\.)?deepnote\.com\/.*/,
Expand Down
2 changes: 1 addition & 1 deletion static/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Codeium",
"description": "Your modern coding superpower. Get code completions in Colab and more.",
"version": "1.2.11",
"version": "1.2.15",
"manifest_version": 3,
"background": {
"service_worker": "serviceWorker.js"
Expand Down
10 changes: 3 additions & 7 deletions webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@ module.exports = {
use: {
loader: 'babel-loader',
options: {
presets: [
'@babel/preset-react',
'@babel/preset-env',
'@babel/preset-typescript',
],
}
presets: ['@babel/preset-react', '@babel/preset-env', '@babel/preset-typescript'],
},
},
exclude: /node_modules/,
},
Expand Down Expand Up @@ -65,5 +61,5 @@ module.exports = {
],
experiments: {
topLevelAwait: true,
}
},
};