Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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 extensions/ql-vscode/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = {
},
],
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-explicit-any": "off",
"prefer-const": ["warn", { destructuring: "all" }],
Expand Down
1,274 changes: 1,095 additions & 179 deletions extensions/ql-vscode/package-lock.json

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions extensions/ql-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"url": "https://github.com/github/vscode-codeql"
},
"engines": {
"vscode": "^1.43.0"
"vscode": "^1.48.0"
},
"categories": [
"Programming Languages"
Expand Down Expand Up @@ -226,6 +226,10 @@
}
},
"commands": [
{
"command": "codeQL.authenticateToGitHub",
"title": "CodeQL: Authenticate to GitHub"
},
{
"command": "codeQL.runQuery",
"title": "CodeQL: Run Query"
Expand Down Expand Up @@ -858,6 +862,7 @@
"format-staged": "lint-staged"
},
"dependencies": {
"@octokit/rest": "^18.5.6",
"child-process-promise": "^2.2.1",
"classnames": "~2.2.6",
"fs-extra": "^9.0.1",
Expand Down Expand Up @@ -906,11 +911,11 @@
"@types/through2": "^2.0.36",
"@types/tmp": "^0.1.0",
"@types/unzipper": "~0.10.1",
"@types/vscode": "^1.43.0",
"@types/vscode": "^1.48.0",
"@types/webpack": "^4.32.1",
"@types/xml2js": "~0.4.4",
"@typescript-eslint/eslint-plugin": "~2.23.0",
"@typescript-eslint/parser": "~2.23.0",
"@typescript-eslint/eslint-plugin": "^4.26.0",
"@typescript-eslint/parser": "^4.26.0",
"ansi-colors": "^4.1.1",
"applicationinsights": "^1.8.7",
"chai": "^4.2.0",
Expand Down Expand Up @@ -938,7 +943,7 @@
"ts-loader": "^8.1.0",
"ts-node": "^8.3.0",
"ts-protoc-gen": "^0.9.0",
"typescript": "~3.8.3",
"typescript": "^4.3.2",
"typescript-formatter": "^7.2.2",
"vsce": "^1.65.0",
"vscode-test": "^1.4.0",
Expand Down
2 changes: 1 addition & 1 deletion extensions/ql-vscode/src/astViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class AstViewerDataProvider extends DisposableObject implements TreeDataProvider
}

refresh(): void {
this._onDidChangeTreeData.fire();
this._onDidChangeTreeData.fire(undefined);
}
getChildren(item?: AstItem): ProviderResult<AstItem[]> {
const children = item ? item.children : this.roots;
Expand Down
59 changes: 59 additions & 0 deletions extensions/ql-vscode/src/authentication.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import * as vscode from 'vscode';
import * as Octokit from '@octokit/rest';

const GITHUB_AUTH_PROVIDER_ID = 'github';

// 'repo' scope should be enough for triggering workflows. For a comprenhensive list, see:
// https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps
const SCOPES = ['repo'];

/**
* Handles authentication to GitHub, using the VS Code [authentication API](https://code.visualstudio.com/api/references/vscode-api#authentication).
*/
export class Credentials {
private octokit: Octokit.Octokit | undefined;

// Explicitly make the constructor private, so that we can't accidentally call the constructor from outside the class
// without also initializing the class.
// eslint-disable-next-line @typescript-eslint/no-empty-function
private constructor() { }
Comment thread
shati-patel marked this conversation as resolved.

static async initialize(context: vscode.ExtensionContext): Promise<Credentials> {
const c = new Credentials();
c.registerListeners(context);
await c.createOctokit(false);
Comment thread
shati-patel marked this conversation as resolved.
Outdated
return c;
}

private async createOctokit(createIfNone: boolean): Promise<Octokit.Octokit | undefined> {
const session = await vscode.authentication.getSession(GITHUB_AUTH_PROVIDER_ID, SCOPES, { createIfNone: createIfNone });
Comment thread
shati-patel marked this conversation as resolved.
Outdated

return session
? new Octokit.Octokit({
auth: session.accessToken
}) : undefined;
}

registerListeners(context: vscode.ExtensionContext): void {
// Sessions are changed when a user logs in or logs out.
context.subscriptions.push(vscode.authentication.onDidChangeSessions(async e => {
if (e.provider.id === GITHUB_AUTH_PROVIDER_ID) {
this.octokit = await this.createOctokit(false);
}
}));
}

async getOctokit(): Promise<Octokit.Octokit> {
if (this.octokit) {
return this.octokit;
}

this.octokit = await this.createOctokit(true);
// octokit shouldn't be undefined, since we've set "createIfNone: true".
// The following block is mainly here to prevent a compiler error.
Comment thread
shati-patel marked this conversation as resolved.
if (!this.octokit) {
throw new Error('Did not initialize Octokit.');
}
Comment thread
shati-patel marked this conversation as resolved.
return this.octokit;
}
}
1 change: 0 additions & 1 deletion extensions/ql-vscode/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/camelcase */
import * as cpp from 'child-process-promise';
import * as child_process from 'child_process';
import * as fs from 'fs-extra';
Expand Down
6 changes: 3 additions & 3 deletions extensions/ql-vscode/src/compare/view/Compare.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const emptyComparison: SetComparisonsMessage = {
message: 'Empty comparison'
};

export function Compare(_: {}): JSX.Element {
export function Compare(_: Record<string, never>): JSX.Element {
const [comparison, setComparison] = useState<SetComparisonsMessage>(
emptyComparison
);
Expand Down Expand Up @@ -66,8 +66,8 @@ export function Compare(_: {}): JSX.Element {
{hasRows ? (
<CompareTable comparison={comparison}></CompareTable>
) : (
<div className="vscode-codeql__compare-message">{message}</div>
)}
<div className="vscode-codeql__compare-message">{message}</div>
)}
</>
);
} catch (err) {
Expand Down
4 changes: 2 additions & 2 deletions extensions/ql-vscode/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export abstract class ConfigListener extends DisposableObject {

protected abstract handleDidChangeConfiguration(e: ConfigurationChangeEvent): void;
private updateConfiguration(): void {
this._onDidChangeConfiguration.fire();
this._onDidChangeConfiguration.fire(undefined);
}

public get onDidChangeConfiguration(): Event<void> {
Expand Down Expand Up @@ -189,7 +189,7 @@ export class QueryServerConfigListener extends ConfigListener implements QuerySe
config.push(distributionManager.onDidChangeDistribution(async () => {
const codeQlPath = await distributionManager.getCodeQlPathWithoutVersionCheck();
config._codeQlPath = codeQlPath!;
config._onDidChangeConfiguration.fire();
config._onDidChangeConfiguration.fire(undefined);
}));
}
return config;
Expand Down
2 changes: 1 addition & 1 deletion extensions/ql-vscode/src/databases-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class DatabaseTreeDataProvider extends DisposableObject

public set sortOrder(newSortOrder: SortOrder) {
this._sortOrder = newSortOrder;
this._onDidChangeTreeData.fire();
this._onDidChangeTreeData.fire(undefined);
}
}

Expand Down
23 changes: 18 additions & 5 deletions extensions/ql-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ import {
} from './commandRunner';
import { CodeQlStatusBarHandler } from './status-bar';

import { Credentials } from './authentication';

/**
* extension.ts
* ------------
Expand Down Expand Up @@ -148,7 +150,7 @@ export interface CodeQLExtensionInterface {
*
* @returns CodeQLExtensionInterface
*/
export async function activate(ctx: ExtensionContext): Promise<CodeQLExtensionInterface | {}> {
export async function activate(ctx: ExtensionContext): Promise<CodeQLExtensionInterface | Record<string, never>> {
logger.log(`Starting ${extensionId} extension`);
if (extension === undefined) {
throw new Error(`Can't find extension ${extensionId}`);
Expand Down Expand Up @@ -294,13 +296,13 @@ export async function activate(ctx: ExtensionContext): Promise<CodeQLExtensionIn

async function installOrUpdateThenTryActivate(
config: DistributionUpdateConfig
): Promise<CodeQLExtensionInterface | {}> {
): Promise<CodeQLExtensionInterface | Record<string, never>> {

await installOrUpdateDistribution(config);

// Display the warnings even if the extension has already activated.
const distributionResult = await getDistributionDisplayingDistributionWarnings();
let extensionInterface: CodeQLExtensionInterface | {} = {};
let extensionInterface: CodeQLExtensionInterface | Record<string, never> = {};
if (!beganMainExtensionActivation && distributionResult.kind !== FindDistributionResultKind.NoDistribution) {
extensionInterface = await activateWithInstalledDistribution(
ctx,
Expand Down Expand Up @@ -494,8 +496,7 @@ async function activateWithInstalledDistribution(
helpers.showAndLogErrorMessage(
'Jumping from a .qlref file to the .ql file it references is not '
+ 'supported with the CLI version you are running.\n'
+ `Please upgrade your CLI to version ${
CliVersionConstraint.CLI_VERSION_WITH_RESOLVE_QLREF
+ `Please upgrade your CLI to version ${CliVersionConstraint.CLI_VERSION_WITH_RESOLVE_QLREF
} or later to use this feature.`);
}
}
Expand Down Expand Up @@ -709,6 +710,18 @@ async function activateWithInstalledDistribution(
helpers.showAndLogInformationMessage(text);
}));

/**
* Credentials for authenticating to GitHub.
* Currently unused, but will be useful in the future when making API calls.
*/
const credentials = await Credentials.initialize(ctx);

ctx.subscriptions.push(
commandRunner('codeQL.authenticateToGitHub', async () => {
const octokit = await credentials.getOctokit();
const userInfo = await octokit.users.getAuthenticated();
helpers.showAndLogInformationMessage(`Authenticated to GitHub as user: ${userInfo.data.login}`);
Comment thread
shati-patel marked this conversation as resolved.
}));

logger.log('Starting language server.');
ctx.subscriptions.push(client.start());
Expand Down
4 changes: 2 additions & 2 deletions extensions/ql-vscode/src/pure/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export interface CompilationTarget {
/**
* Compile as a normal query
*/
query?: {};
query?: Record<string, never>;
/**
* Compile as a quick evaluation
*/
Expand Down Expand Up @@ -826,7 +826,7 @@ export interface ResultSet {
/**
* The type returned when the evaluation is complete
*/
export type EvaluationComplete = {};
export type EvaluationComplete = Record<string, never>;

/**
* The result of a single query
Expand Down
2 changes: 1 addition & 1 deletion extensions/ql-vscode/src/qltest-discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export class QLTestDiscovery extends Discovery<QLTestDiscoveryResults> {
this.watcher.addWatch(new RelativePattern(results.watchPath, '**/*.{ql,qlref}'));
// need to explicitly watch for changes to directories themselves.
this.watcher.addWatch(new RelativePattern(results.watchPath, '**/'));
this._onDidChangeTests.fire();
this._onDidChangeTests.fire(undefined);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion extensions/ql-vscode/src/query-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export class HistoryTreeDataProvider extends DisposableObject {

public set sortOrder(newSortOrder: SortOrder) {
this._sortOrder = newSortOrder;
this._onDidChangeTreeData.fire();
this._onDidChangeTreeData.fire(undefined);
}
}

Expand Down
2 changes: 1 addition & 1 deletion extensions/ql-vscode/src/view/raw-results-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type RawTableProps = ResultTableProps & {
offset: number;
};

export class RawTable extends React.Component<RawTableProps, {}> {
export class RawTable extends React.Component<RawTableProps, Record<string, never>> {
constructor(props: RawTableProps) {
super(props);
}
Expand Down
4 changes: 2 additions & 2 deletions extensions/ql-vscode/src/view/result-tables.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class ResultTables

private getResultSets(): ResultSet[] {
const resultSets: ResultSet[] =
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore 2783
this.props.rawResultSets.map((rs) => ({ t: 'RawResultSet', ...rs }));

Expand Down Expand Up @@ -336,7 +336,7 @@ export class ResultTables
}
}

class ResultTable extends React.Component<ResultTableProps, {}> {
class ResultTable extends React.Component<ResultTableProps, Record<string, never>> {

constructor(props: ResultTableProps) {
super(props);
Expand Down
2 changes: 1 addition & 1 deletion extensions/ql-vscode/src/view/results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const onNavigation = new EventHandlerList<NavigationEvent>();
/**
* A minimal state container for displaying results.
*/
class App extends React.Component<{}, ResultsViewState> {
class App extends React.Component<Record<string, never>, ResultsViewState> {
constructor(props: any) {
super(props);
this.state = {
Expand Down
14 changes: 14 additions & 0 deletions extensions/ql-vscode/src/vscode-tests/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
module.exports = {
env: {
mocha: true
},
rules: {
"@typescript-eslint/ban-types": [
"error",
{
// For a full list of the default banned types, see:
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md
extendDefaults: true,
"types": {
// Don't complain about the `Function` type in test files. (Default is `true`.)
"Function": false,
}
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('Databases', function() {

beforeEach(async () => {
try {
const extension = await extensions.getExtension<CodeQLExtensionInterface | {}>('GitHub.vscode-codeql')!.activate();
const extension = await extensions.getExtension<CodeQLExtensionInterface | Record<string, never>>('GitHub.vscode-codeql')!.activate();
if ('databaseManager' in extension) {
databaseManager = extension.databaseManager;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default function(mocha: Mocha) {
// ensure etension is cleaned up.
(mocha.options as any).globalTeardown.push(
async () => {
const extension = await extensions.getExtension<CodeQLExtensionInterface | {}>('GitHub.vscode-codeql')!.activate();
const extension = await extensions.getExtension<CodeQLExtensionInterface | Record<string, never>>('GitHub.vscode-codeql')!.activate();
// This shuts down the extension and can only be run after all tests have completed.
// If this is not called, then the test process will hang.
if ('dispose' in extension) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('Queries', function() {
sandbox = sinon.createSandbox();

try {
const extension = await extensions.getExtension<CodeQLExtensionInterface | {}>('GitHub.vscode-codeql')!.activate();
const extension = await extensions.getExtension<CodeQLExtensionInterface | Record<string, never>>('GitHub.vscode-codeql')!.activate();
if ('databaseManager' in extension) {
databaseManager = extension.databaseManager;
cli = extension.cliServer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Checkpoint<T> {
this.res = () => { /**/ };
this.rej = () => { /**/ };
this.promise = new Promise((res, rej) => {
this.res = res as () => {};
this.res = res as () => Record<string, never>;
this.rej = rej;
});
}
Expand Down Expand Up @@ -104,7 +104,7 @@ describe('using the query server', function() {

beforeEach(async () => {
try {
const extension = await extensions.getExtension<CodeQLExtensionInterface | {}>('GitHub.vscode-codeql')!.activate();
const extension = await extensions.getExtension<CodeQLExtensionInterface | Record<string, never>>('GitHub.vscode-codeql')!.activate();
if ('cliServer' in extension && 'qs' in extension) {
cliServer = extension.cliServer;
qs = extension.qs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('Use cli', function() {
let cli: CodeQLCliServer;

beforeEach(async () => {
const extension = await extensions.getExtension<CodeQLExtensionInterface | {}>('GitHub.vscode-codeql')!.activate();
const extension = await extensions.getExtension<CodeQLExtensionInterface | Record<string, never>>('GitHub.vscode-codeql')!.activate();
if ('cliServer' in extension) {
cli = extension.cliServer;
} else {
Expand Down
1 change: 1 addition & 0 deletions extensions/ql-vscode/src/vscode-tests/index-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export async function runTestsInDirectory(testsRoot: string, useCli = false): Pr
.filter(f => f.endsWith('.helper.js'))
.forEach(f => {
console.log(`Executing helper ${f}`);
// eslint-disable-next-line @typescript-eslint/no-var-requires
const helper = require(path.resolve(testsRoot, f)).default;
helper(mocha);
});
Expand Down
Loading