Skip to content

Commit

Permalink
Merge branch 'main' into fix/noSuggestionDiagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
qingniaotonghua authored Sep 11, 2023
2 parents b61ed73 + 51ba677 commit 42cceba
Show file tree
Hide file tree
Showing 13 changed files with 736 additions and 578 deletions.
4 changes: 2 additions & 2 deletions test/manual/dev-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
'npm/dev': 'node_modules/monaco-editor-core/dev/vs',
'npm/min': 'node_modules/monaco-editor-core/min/vs',
built: '/vscode/out-monaco-editor-core/min/vs',
releaseDev: 'release/dev/vs',
releaseMin: 'release/min/vs'
releaseDev: 'out/monaco-editor/dev/vs',
releaseMin: 'out/monaco-editor/min/vs'
};
const pluginPaths = {
src: 'out/amd',
Expand Down
2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"mini-css-extract-plugin": "^2.6.1",
"mobx": "^5.15.4",
"mobx-react": "^6.2.2",
"monaco-editor": "^0.35.0",
"monaco-editor": "^0.42.0-dev-20230906",
"react": "^17.0.2",
"react-bootstrap": "^2.4.0",
"react-dom": "^17.0.2",
Expand Down
2 changes: 1 addition & 1 deletion website/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ export interface IPlaygroundProject {
}

export interface IPreviewState extends IPlaygroundProject {
key: number;
reloadKey: number;
monacoSetup: IMonacoSetup;
}
161 changes: 161 additions & 0 deletions website/src/website/pages/playground/BisectModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import { action, ObservableMap } from "mobx";
import {
getNpmVersions,
getNpmVersionsSync,
getVsCodeCommitId,
} from "./getNpmVersionsSync";
import { PlaygroundModel } from "./PlaygroundModel";
import { findLastIndex } from "./utils";

export class BisectModel {
private readonly map = new ObservableMap<string, boolean>();

constructor(private readonly model: PlaygroundModel) {}

public getState(version: string): boolean | undefined {
return this.map.get(version);
}

public get isActive() {
return [...this.map.values()].some((e) => e !== undefined);
}

public reset(): void {
this.map.clear();
}

public async toggleState(version: string, state: boolean): Promise<void> {
const currentState = this.getState(version);
await this.setState(
version,
currentState === state ? undefined : state
);
}

@action
public async setState(
version: string,
state: boolean | undefined
): Promise<void> {
if (state === undefined) {
this.map.delete(version);
} else {
this.map.set(version, state);
}

const nextVersion = await this.getNextVersion();
if (!nextVersion) {
return;
}
this.model.settings.setSettings({
...this.model.settings.settings,
npmVersion: nextVersion,
});
}

private get versions() {
return getNpmVersionsSync(undefined);
}

private get indexOfLastBadVersion() {
return findLastIndex(this.versions, (v) => this.map.get(v) === false);
}
private get indexOfFirstGoodVersion() {
return this.versions.findIndex((v) => this.map.get(v) === true);
}

public get steps() {
const indexOfFirstGoodVersion = this.indexOfFirstGoodVersion;
const indexOfLastBadVersion = this.indexOfLastBadVersion;

if (indexOfFirstGoodVersion === -1 && indexOfLastBadVersion === -1) {
return -1;
}
if (indexOfFirstGoodVersion === -1) {
return Math.ceil(
Math.log2(this.versions.length - indexOfLastBadVersion)
);
} else if (indexOfLastBadVersion === -1) {
return Math.ceil(Math.log2(indexOfFirstGoodVersion + 1));
} else {
return Math.ceil(
Math.log2(indexOfFirstGoodVersion - indexOfLastBadVersion)
);
}
}

public get isFinished() {
if (
this.indexOfFirstGoodVersion !== -1 &&
this.indexOfLastBadVersion + 1 === this.indexOfFirstGoodVersion
) {
return true;
}
return false;
}

public async openGithub() {
const versions = await getNpmVersions();
const indexOfFirstGoodVersion =
this.indexOfFirstGoodVersion === -1
? versions.length - 1
: this.indexOfFirstGoodVersion;
const indexOfLastBadVersion =
this.indexOfLastBadVersion === -1 ? 0 : this.indexOfLastBadVersion;
const goodCommitId = await getVsCodeCommitId(
versions[indexOfFirstGoodVersion]
);
const badCommitId = await getVsCodeCommitId(
versions[indexOfLastBadVersion]
);
window.open(
`https://github.com/microsoft/vscode/compare/${goodCommitId}...${badCommitId}`,
"_blank"
);
}

private async getNextVersion(): Promise<string | undefined> {
const versions = await getNpmVersions();

const indexOfFirstGoodVersion = this.indexOfFirstGoodVersion;
const indexOfLastBadVersion = this.indexOfLastBadVersion;

if (
indexOfFirstGoodVersion !== -1 &&
indexOfLastBadVersion + 1 === indexOfFirstGoodVersion
) {
// Finished
return;
}

if (indexOfLastBadVersion === -1 && indexOfFirstGoodVersion === -1) {
return versions[0];
}
if (indexOfLastBadVersion === -1) {
// try first (newest) version that hasn't been tested
const indexOfFirstUntestedVersion = versions.findIndex(
(v) => this.map.get(v) === undefined
);
if (indexOfFirstUntestedVersion === -1) {
return undefined;
}
return versions[indexOfFirstUntestedVersion];
}

if (indexOfFirstGoodVersion === -1) {
/*// exponential back off, might be good for recent regressions, but ruins step counter
const candidate = Math.min(
indexOfLastBadVersion * 2 + 1,
versions.length - 1
);*/
const candidate = Math.floor(
(indexOfLastBadVersion + versions.length) / 2
);
return versions[candidate];
}

return versions[
Math.floor((indexOfLastBadVersion + indexOfFirstGoodVersion) / 2)
];
}
}
Loading

0 comments on commit 42cceba

Please sign in to comment.