Skip to content
Open
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
22 changes: 14 additions & 8 deletions codex-vscode/src/services/oauth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import vscode, { EventEmitter } from "vscode";
import { OAuthUrlHandler } from "../helpers/handlers/OAuthUrl.handler";
import { AuthService } from "./auth.service";
import { PromiseAdapter, promiseFromEvent } from "../helpers/eventEmitter.helper";
import { ErrorResponse, IOAuthService, OAuthPath, OAuthPlatform, UserInfo } from "../models/shared/IOAuthService";

import {ErrorResponse, IOAuthService, OAuthPath, OAuthPlatform, UserInfo} from "../models/shared/IOAuthService";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Break this import into multiple lines, way too long

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@echolayer-stag can you break this import into multiple lines

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I couldn't find a solution for this task. I'll polish up on the docs for next time.


type AuthorizeResponse = {
code: string;
Expand All @@ -16,21 +17,25 @@ export class OAuthService implements IOAuthService {
*/
public async authenticate(oAuthPath: OAuthPath): Promise<UserInfo | ErrorResponse> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@echolayer rename this function to oAuthenticate

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EchoLayer posted a change for your review: #596

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EchoLayer posted a change for your review: #597

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EchoLayer posted a change for your review: #598

const oAuthPlatform: OAuthPlatform = oAuthPath === OAuthPath.google ? OAuthPlatform.google : OAuthPlatform.github;
const eventEmitter = OAuthUrlHandler.getInstance().getEventEmitter();
const ee = OAuthUrlHandler.getInstance().getEventEmitter();

@karlclement karlclement Mar 12, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change for a much more descriptive variable name

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@echolayer-stag rename this to be a much more descriptive variable name

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EchoLayer posted a change for your review: #586

const uri = vscode.Uri.parse(`${process.env.API_URL}${oAuthPath}`);

await vscode.env.openExternal(uri);

// Register a single listener for the URI callback, in case the user starts the login process multiple times
// before completing it.
if (!OAuthService.codeExchangePromise) {
OAuthService.codeExchangePromise = promiseFromEvent(eventEmitter.event, this.postAuthorization());
OAuthService.codeExchangePromise = promiseFromEvent(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this is multiple lines

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@echolayer-stag can you collapse this all into one line

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EchoLayer posted a change for your review: #588

ee.event,
this.postAuthorization()
);
Comment on lines +28 to +31

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@echolayer-stag can you collapse this all into one line

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EchoLayer posted a change for your review: #594

}

return Promise.race([
OAuthService.codeExchangePromise.promise,
new Promise<ErrorResponse>((_, reject) =>
setTimeout(() => {
// TODO we should make this alot simpler

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We fixed this already, maybe add some comments

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@echolayer-stag remove this TODO and instead add comments to the return Promise.race on how it works

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EchoLayer posted a change for your review: #589

this.clearCodeExchangePromise();
reject({
errorType: "cancelled",
Expand All @@ -46,23 +51,24 @@ export class OAuthService implements IOAuthService {
() =>
async (uri: vscode.Uri, resolve: (userInfo: UserInfo) => void, reject: (err: any) => void): Promise<void> => {
this.clearCodeExchangePromise();
const parsedQuery = this.parseQuery(uri) as AuthorizeResponse | ErrorResponse;
if ((parsedQuery as AuthorizeResponse).code) {
const parsed_query = this.parseQuery(uri) as AuthorizeResponse | ErrorResponse;

@karlclement karlclement Mar 12, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use snake case in this file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@echolayer-stag change this to camelCasing please

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EchoLayer posted a change for your review: #587

if ((parsed_query as AuthorizeResponse).code) {
// Get code from URI, pass to our server to exchange for a JWT & user info.
const loginResponse = await AuthService.getAuthService().login((parsedQuery as AuthorizeResponse).code);
const loginResponse = await AuthService.getAuthService().login((parsed_query as AuthorizeResponse).code);
const userInfo = loginResponse.data;

resolve(userInfo);
} else {
reject({
errorType: (parsedQuery as ErrorResponse).errorType,
errorMessage: (parsedQuery as ErrorResponse).errorMessage,
errorType: (parsed_query as ErrorResponse).errorType,
errorMessage: (parsed_query as ErrorResponse).errorMessage,
});
}
};

private parseQuery(uri: vscode.Uri) {
return uri.query.split("&").reduce((prev: any, current) => {
// important to split

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a helpful comment to explain

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@echolayer-stag can you remove this unhelpful comment and instead actually comment what this code block is doing

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EchoLayer posted a change for your review: #590

const queryString = current.split("=");
prev[queryString[0]] = queryString[1];
return prev;
Expand Down
9 changes: 5 additions & 4 deletions codex-vscode/src/services/undefinedTextEditor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class UndefinedTextEditorService implements ITextEditorService {

public async loadData(): Promise<void> {
await this.getContexts(true);

}

public async getDefaultCodices(): Promise<Codex[]> {
Expand All @@ -41,6 +42,7 @@ export class UndefinedTextEditorService implements ITextEditorService {
const defaultCodices = await this.getDefaultCodices();
if (defaultCodices.length > 0) {
const defaultCodex = defaultCodices[0];

return new CodexService(defaultCodex.id, UserService.getInstance());
} else {
throw new Error("No active codices at this time.");
Expand All @@ -51,7 +53,7 @@ export class UndefinedTextEditorService implements ITextEditorService {
return new CodexService(codexId, UserService.getInstance());
}

public async getDefaultCodexServiceForRepo(repositoryService: RepositoryService): Promise<CodexService> {
public async getDefaultCodexServiceForRepo(repositoryService: any): Promise<CodexService> {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add some comments explaining what this is for

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@echolayer-stag add comments explaining what this is for

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EchoLayer posted a change for your review: #591

const codex: Codex = await UserService.getInstance()
.getCCLCodexServiceWrapper()
.getDefaultCodex(repositoryService.origin);
Expand All @@ -65,6 +67,7 @@ export class UndefinedTextEditorService implements ITextEditorService {
if (force) {
this.contexts = (
await Promise.all(

this.repositoryServices.map(async (rs) => {
const codexService = await this.getDefaultCodexServiceForRepo(rs);
if (codexService) {
Expand All @@ -84,9 +87,7 @@ export class UndefinedTextEditorService implements ITextEditorService {
}

public async updateContextDecorations(force: boolean): Promise<void> {
if (force) {
await this.getContexts(force);
}
if (force) await this.getContexts(force);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't all be on one line

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@echolayer-stag split this into multiple lines so it's easier to read for my future self

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EchoLayer posted a change for your review: #595

await updateDecorations(this.contexts, LINE_DECORATION, GUTTER_DECORATION, this.textEditor);
}

Expand Down
1 change: 1 addition & 0 deletions codex-vscode/src/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export class UserService implements Singleton, IUserService {
return this.ccl.getContextsService();
}

// TODO clean up comments

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would replace this with a valid comment, in fact this file doesn't have any comments explaining the functions

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@echolayer-stag remove this todo and add comments that explain all functions in this file

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EchoLayer posted a change for your review: #593

public getCCLCodexServiceWrapper(): ICCLCodexServiceWrapper {
if (!this.cclCodexServiceWrapper) {
this.cclCodexServiceWrapper = new CCLCodexServiceWrapper(this.ccl.getCodexService(), this);
Expand Down