Skip to content

Commit

Permalink
Load projects based on bsconfig.json presence (#613)
Browse files Browse the repository at this point in the history
* Load projects based on bsconfig.json presence

* More unit tests.

* Clean up some unit tests

* Rename `workspace` to `project`

* more test workspace -> project  var renames

* don't create duplicate projects
  • Loading branch information
TwitchBronBron authored Jun 7, 2022
1 parent 3bdb197 commit 638fde4
Show file tree
Hide file tree
Showing 10 changed files with 541 additions and 378 deletions.
6 changes: 3 additions & 3 deletions benchmarks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { spawnSync, execSync } = require('child_process');
const yargs = require('yargs');
const readline = require('readline');
const rimraf = require('rimraf');
const glob = require('glob');
const fastGlob = require('fast-glob');
let nodeParams = ['--max-old-space-size=8192'];
const tempDir = path.join(__dirname, '.tmp');

Expand Down Expand Up @@ -153,7 +153,7 @@ class Runner {
const alias = `brighterscript${versionIndex + 1}`;

//get the list of current profiler logs
const beforeLogs = glob.sync('isolate-*.log', {
const beforeLogs = fastGlob.sync('isolate-*.log', {
cwd: __dirname
});

Expand All @@ -162,7 +162,7 @@ class Runner {
stdio: 'inherit'
});
if (this.profile) {
const logFile = glob.sync('isolate-*.log', {
const logFile = fastGlob.sync('isolate-*.log', {
cwd: __dirname
}).filter(x => !beforeLogs.includes(x))[0];

Expand Down
57 changes: 18 additions & 39 deletions package-lock.json

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

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
"@types/command-line-usage": "^5.0.1",
"@types/debounce-promise": "^3.1.1",
"@types/fs-extra": "^8.0.0",
"@types/glob": "^7.1.1",
"@types/marked": "^4.0.3",
"@types/mocha": "^5.2.5",
"@types/node": "^11.9.0",
Expand Down Expand Up @@ -130,9 +129,9 @@
"cross-platform-clear-console": "^2.3.0",
"debounce-promise": "^3.1.0",
"eventemitter3": "^4.0.0",
"fast-glob": "^3.2.11",
"file-url": "^3.0.0",
"fs-extra": "^8.0.0",
"glob": "^7.1.6",
"jsonc-parser": "^2.3.0",
"long": "^3.2.0",
"luxon": "^1.8.3",
Expand Down
5 changes: 3 additions & 2 deletions scripts/compile-doc-examples.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fsExtra from 'fs-extra';
import * as glob from 'glob';
import * as fastGlob from 'fast-glob';
import * as path from 'path';
import { Program } from '../src/Program';
import type { BsConfig } from '../src';
Expand All @@ -16,6 +16,7 @@ class DocCompiler {
) {

}

private lines: string[];
private index: number;
private bsconfig: BsConfig;
Expand Down Expand Up @@ -195,7 +196,7 @@ class DocCompiler {
const docsFolder = path.resolve(
path.join(__dirname, '..', 'docs')
);
const docs = glob.sync('**/*.md', {
const docs = fastGlob.sync('**/*.md', {
cwd: docsFolder,
absolute: true
});
Expand Down
10 changes: 5 additions & 5 deletions src/DiagnosticCollection.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { BsDiagnostic } from '.';
import { DiagnosticCollection } from './DiagnosticCollection';
import type { Workspace } from './LanguageServer';
import type { Project } from './LanguageServer';
import type { ProgramBuilder } from './ProgramBuilder';
import type { BscFile } from './interfaces';
import util from './util';
Expand All @@ -9,21 +9,21 @@ import { expect } from 'chai';
describe('DiagnosticCollection', () => {
let collection: DiagnosticCollection;
let diagnostics: BsDiagnostic[];
let workspaces: Workspace[];
let projects: Project[];
beforeEach(() => {
collection = new DiagnosticCollection();
diagnostics = [];
//make simple mock of workspace to pass tests
workspaces = [{
projects = [{
firstRunPromise: Promise.resolve(),
builder: {
getDiagnostics: () => diagnostics
} as ProgramBuilder
}] as Workspace[];
}] as Project[];
});

async function testPatch(expected: Record<string, string[]>) {
const patch = await collection.getPatch(workspaces);
const patch = await collection.getPatch(projects);
//convert the patch into our test structure
const actual = {};
for (const filePath in patch) {
Expand Down
14 changes: 7 additions & 7 deletions src/DiagnosticCollection.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { BsDiagnostic } from './interfaces';
import type { Workspace } from './LanguageServer';
import type { Project } from './LanguageServer';

export class DiagnosticCollection {
private previousDiagnosticsByFile = {} as Record<string, KeyedDiagnostic[]>;

public async getPatch(workspaces: Workspace[]): Promise<Record<string, KeyedDiagnostic[]>> {
const diagnosticsByFile = await this.getDiagnosticsByFileFromWorkspaces(workspaces);
public async getPatch(projects: Project[]): Promise<Record<string, KeyedDiagnostic[]>> {
const diagnosticsByFile = await this.getDiagnosticsByFileFromProjects(projects);

const patch = {
...this.getRemovedPatch(diagnosticsByFile),
Expand All @@ -18,17 +18,17 @@ export class DiagnosticCollection {
return patch;
}

private async getDiagnosticsByFileFromWorkspaces(workspaces: Workspace[]) {
private async getDiagnosticsByFileFromProjects(projects: Project[]) {
const result = {} as Record<string, KeyedDiagnostic[]>;

//wait for all programs to finish running. This ensures the `Program` exists.
await Promise.all(
workspaces.map(x => x.firstRunPromise)
projects.map(x => x.firstRunPromise)
);

//get all diagnostics for all workspaces
//get all diagnostics for all projects
let diagnostics = Array.prototype.concat.apply([] as KeyedDiagnostic[],
workspaces.map((x) => x.builder.getDiagnostics())
projects.map((x) => x.builder.getDiagnostics())
) as KeyedDiagnostic[];

const keys = {};
Expand Down
Loading

0 comments on commit 638fde4

Please sign in to comment.