Skip to content

Commit

Permalink
Project import generated by Copybara. (#24)
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 17156de34695d0119eeb1cf788f55e9d4a9bc18c

Co-authored-by: Copybara Bot <[email protected]>
  • Loading branch information
pqn and Copybara Bot authored Aug 2, 2023
1 parent 53351b4 commit 44f78e1
Show file tree
Hide file tree
Showing 24 changed files with 288 additions and 142 deletions.
5 changes: 3 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
}
],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["error"],
"@typescript-eslint/no-unnecessary-condition": "off"
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-unnecessary-condition": "off",
"@typescript-eslint/no-floating-promises": "error"
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
.DS_Store
proto
dist.zip
dist_enterprise.zip
14 changes: 12 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

set -euxo pipefail

if [[ "$1" != "public" && "$1" != "enterprise" ]]; then
echo "Usage: $0 <public|enterprise>"
exit 1
fi

branch=$(git rev-parse --abbrev-ref HEAD)
if [ "$branch" != "main" ]; then
echo "Use main branch only"
Expand All @@ -12,6 +17,11 @@ git diff-index --quiet HEAD

cd -- "$( dirname -- "${BASH_SOURCE[0]}" )"

git clean -ffdx
cd ../../.. && git clean -ffdx && cd -
npm install
npm run build
# If the first arg is public, use npm run build
if [[ "$1" == "public" ]]; then
npm run build
else
npm run build:enterprise
fi
34 changes: 17 additions & 17 deletions package-lock.json

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

14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{
"name": "chrome-extension-webpack",
"version": "1.2.52",
"description": "Get started with Chrome extensions development using webpack, Typescript, Sass, and more",
"name": "codeium-chrome",
"version": "1.2.58",
"description": "",
"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,.tsx --max-warnings=0 .",
"start:enterprise": "npm run generate && webpack --watch --config webpack.dev.js --env enterprise",
"build": "npm run generate && npm run lint && webpack --config webpack.prod.js && cd dist && zip -r ../dist.zip .",
"build:enterprise": "npm run generate && npm run lint && webpack --config webpack.prod.js --env enterprise && cd dist && zip -r ../dist_enterprise.zip .",
"lint": "tsc --noEmit && eslint --ext .ts,.tsx --max-warnings=0 .",
"prettier": "prettier --write .",
"prettier:check": "prettier --check .",
"postinstall": "patch-package"
Expand All @@ -25,7 +27,7 @@
"@jupyterlab/codemirror": "^3.5.2",
"@jupyterlab/fileeditor": "^3.5.2",
"@jupyterlab/notebook": "^3.5.2",
"@types/chrome": "^0.0.235",
"@types/chrome": "^0.0.242",
"@types/codemirror": "^5.60.6",
"@types/react-dom": "^18.2.1",
"@types/uuid": "^9.0.1",
Expand Down
6 changes: 6 additions & 0 deletions src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export async function openAuthTab(): Promise<void> {
},
});
const profileUrl = await getGeneralProfileUrl();
if (profileUrl === undefined) {
return;
}

await chrome.tabs.create({
url: `${profileUrl}?redirect_uri=chrome-extension://${chrome.runtime.id}&state=${uuid}`,
Expand All @@ -27,6 +30,9 @@ export async function registerUser(
): Promise<{ api_key: string; name: string }> {
const url = ((): URL => {
if (portalUrl === undefined) {
if (CODEIUM_ENTERPRISE) {
throw new Error('portalUrl is undefined');
}
return new URL('register_user/', 'https://api.codeium.com');
}
return new URL('_route/api_server/exa.api_server_pb.ApiServerService/RegisterUser', portalUrl);
Expand Down
2 changes: 1 addition & 1 deletion src/codemirrorInject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class CodeMirrorState {
}
}

this.codeMirrorManager.triggerCompletion(
await this.codeMirrorManager.triggerCompletion(
this.docs,
editor.getDoc(),
new EditorOptions({
Expand Down
18 changes: 11 additions & 7 deletions 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.52';
const EXTENSION_VERSION = '1.2.58';

export const CODEIUM_DEBUG = false;

Expand Down Expand Up @@ -53,12 +53,16 @@ export interface IdeInfo {

export class LanguageServerServiceWorkerClient {
// Note that the URL won't refresh post-initialization.
client: Promise<PromiseClient<typeof LanguageServerService>>;
client: Promise<PromiseClient<typeof LanguageServerService> | undefined>;
private abortController?: AbortController;

constructor(baseUrlPromise: Promise<string>, private readonly sessionId: string) {
this.client = (async (): Promise<PromiseClient<typeof LanguageServerService>> => {
return languageServerClient(await baseUrlPromise);
constructor(baseUrlPromise: Promise<string | undefined>, private readonly sessionId: string) {
this.client = (async (): Promise<PromiseClient<typeof LanguageServerService> | undefined> => {
const baseUrl = await baseUrlPromise;
if (baseUrl === undefined) {
return undefined;
}
return languageServerClient(baseUrl);
})();
}

Expand All @@ -76,7 +80,7 @@ export class LanguageServerServiceWorkerClient {
this.abortController?.abort();
this.abortController = new AbortController();
const signal = this.abortController.signal;
const getCompletionsPromise = (await this.client).getCompletions(request, {
const getCompletionsPromise = (await this.client)?.getCompletions(request, {
signal,
headers: this.getHeaders(request.metadata?.apiKey),
});
Expand Down Expand Up @@ -111,7 +115,7 @@ export class LanguageServerServiceWorkerClient {
try {
await (
await this.client
).acceptCompletion(acceptCompletionRequest, {
)?.acceptCompletion(acceptCompletionRequest, {
headers: this.getHeaders(acceptCompletionRequest.metadata?.apiKey),
});
} catch (err) {
Expand Down
69 changes: 40 additions & 29 deletions src/component/Options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ const EditableList = () => {
(async () => {
const allowlist = computeAllowlist(await getStorageItem('allowlist'));
setText(allowlist.join('\n'));
})();
})().catch((e) => {
console.error(e);
});
}, []);

return (
Expand All @@ -54,7 +56,7 @@ const EditableList = () => {

<Button
variant="text"
onClick={() => {
onClick={async () => {
const lst = text
.split('\n')
.map((x) => x.trim())
Expand All @@ -69,7 +71,7 @@ const EditableList = () => {
return;
}
}
setStorageItem('allowlist', { defaults: defaultAllowlist, current: lst });
await setStorageItem('allowlist', { defaults: defaultAllowlist, current: lst });
setSeverity('success');
setMessage('Saved successfully');
setOpen(true);
Expand Down Expand Up @@ -123,8 +125,11 @@ const EditableList = () => {
);
};

const profileUrl = getGeneralProfileUrl();
const openTokenPage = async () => {
const profileUrl = await getGeneralProfileUrl();
if (profileUrl === undefined) {
return;
}
const params = new URLSearchParams({
response_type: 'token',
redirect_uri: 'chrome-show-auth-token',
Expand All @@ -133,7 +138,7 @@ const openTokenPage = async () => {
redirect_parameters_type: 'query',
state: uuidv4(),
});
await chrome.tabs.create({ url: `${await profileUrl}?${params}` });
await chrome.tabs.create({ url: `${profileUrl}?${params}` });
};

const Options = () => {
Expand All @@ -143,36 +148,42 @@ const Options = () => {
useEffect(() => {
(async () => {
setPortalUrlText((await getStorageItem('portalUrl')) ?? '');
})();
})().catch((e) => {
console.error(e);
});
}, []);
return (
<Box sx={{ width: '100%', maxWidth: 400, bgcolor: 'background.paper' }}>
<Typography variant="body2">
<SettingsIcon
fontSize="small"
sx={{
verticalAlign: 'bottom',
marginRight: '0.2em',
marginLeft: '0.4em',
bottom: '-0.1em',
}}
/>{' '}
Edit telemetry settings at the{' '}
<Link href="https://codeium.com/profile" target="_blank">
Codeium website
<OpenInNewIcon
fontSize="small"
{!CODEIUM_ENTERPRISE && (
<>
<Typography variant="body2">
<SettingsIcon
fontSize="small"
sx={{
verticalAlign: 'bottom',
marginRight: '0.2em',
marginLeft: '0.4em',
bottom: '-0.1em',
}}
/>{' '}
Edit telemetry settings at the{' '}
<Link href="https://codeium.com/profile" target="_blank">
Codeium website
<OpenInNewIcon
fontSize="small"
sx={{
verticalAlign: 'bottom',
}}
/>
</Link>
</Typography>
<Divider
sx={{
verticalAlign: 'bottom',
padding: '0.5em',
}}
/>
</Link>
</Typography>
<Divider
sx={{
padding: '0.5em',
}}
/>
</>
)}
<Box sx={{ my: 2, mx: 2 }}>
<Typography variant="h6"> Alternative ways to log in </Typography>
<TextField
Expand Down
2 changes: 2 additions & 0 deletions src/enterprise.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Defined in webpack.common.js.
declare const CODEIUM_ENTERPRISE: boolean;
2 changes: 1 addition & 1 deletion src/jupyterInject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class JupyterState {
}
const textModels = this.notebook.get_cells().map((cell) => cell.code_mirror.getDoc());

codeMirrorManager.triggerCompletion(
await codeMirrorManager.triggerCompletion(
textModels,
this.code_mirror.getDoc(),
new EditorOptions({
Expand Down
2 changes: 1 addition & 1 deletion src/jupyterlabPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class CodeiumPlugin {
]
);
});
chrome.runtime.sendMessage(this.extensionId, { type: 'success' }); // no await
void chrome.runtime.sendMessage(this.extensionId, { type: 'success' });
return false;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/monacoCompletionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,9 @@ export class MonacoCompletionProvider implements monaco.languages.InlineCompleti
}

addEditor(editor: monaco.editor.ICodeEditor): void {
editor.updateOptions({ inlineSuggest: { enabled: true } });
if (this.monacoSite !== OMonacoSite.DATABRICKS) {
editor.updateOptions({ inlineSuggest: { enabled: true } });
}
const uri = editor.getModel()?.uri.toString();
if (uri !== undefined) {
this.modelUriToEditor.set(uri, editor);
Expand Down
Loading

0 comments on commit 44f78e1

Please sign in to comment.