lean4monaco 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ export declare function setUserAgent(window: any, userAgent: any): void;
@@ -0,0 +1,31 @@
1
+ export function setUserAgent(window, userAgent) {
2
+ // Works on Firefox, Chrome, Opera and IE9+
3
+ if (navigator.__defineGetter__) {
4
+ navigator.__defineGetter__('userAgent', function () {
5
+ return userAgent;
6
+ });
7
+ }
8
+ else if (Object.defineProperty) {
9
+ Object.defineProperty(navigator, 'userAgent', {
10
+ get: function () {
11
+ return userAgent;
12
+ }
13
+ });
14
+ }
15
+ // Works on Safari
16
+ if (window.navigator.userAgent !== userAgent) {
17
+ var userAgentProp = {
18
+ get: function () {
19
+ return userAgent;
20
+ }
21
+ };
22
+ try {
23
+ Object.defineProperty(window.navigator, 'userAgent', userAgentProp);
24
+ }
25
+ catch (e) {
26
+ window.navigator = Object.create(navigator, {
27
+ userAgent: userAgentProp
28
+ });
29
+ }
30
+ }
31
+ }
@@ -313,7 +313,9 @@ export class LeanClient {
313
313
  return true;
314
314
  }
315
315
  if (this.folderUri.scheme === 'file' && uri.scheme === 'file') {
316
- return uri.isInFolder(this.folderUri);
316
+ // lean4monaco: To avoid file system issues, we let any client manage any file:
317
+ return true;
318
+ // return uri.isInFolder(this.folderUri)
317
319
  }
318
320
  return false;
319
321
  }
@@ -168,8 +168,6 @@ export class LeanClientProvider {
168
168
  bestCandidate = candidate;
169
169
  }
170
170
  }
171
- // lean4monaco: Due to issues with Windows file paths, we assume for now that there is only one client.
172
- return this.getClients()[0];
173
171
  return bestCandidate;
174
172
  }
175
173
  getClients() {
@@ -1,6 +1,6 @@
1
1
  import * as fs from 'fs';
2
2
  import path from 'path';
3
- import { FileUri, isWorkspaceFolder, UntitledUri } from './exturi';
3
+ import { FileUri, UntitledUri } from './exturi';
4
4
  import { dirExists, fileExists } from './fsHelper';
5
5
  // Detect lean4 root directory (works for both lean4 repo and nightly distribution)
6
6
  export async function isCoreLean4Directory(path) {
@@ -26,57 +26,58 @@ export async function findLeanProjectRootInfo(uri) {
26
26
  if (uri.scheme === 'untitled') {
27
27
  return { kind: 'Success', projectRootUri: new UntitledUri(), toolchainUri: undefined };
28
28
  }
29
- let path = uri;
29
+ // lean4monaco: Prevent filesystem access:
30
+ return { kind: 'Success', projectRootUri: uri.join('..'), toolchainUri: undefined };
31
+ /*
32
+ let path = uri
30
33
  try {
31
34
  if ((await fs.promises.stat(path.fsPath)).isFile()) {
32
- path = uri.join('..');
35
+ path = uri.join('..')
33
36
  }
37
+ } catch (e) {
38
+ return { kind: 'FileNotFound' }
34
39
  }
35
- catch (e) {
36
- return { kind: 'FileNotFound' };
37
- }
38
- let bestFolder = path;
39
- let bestLeanToolchain;
40
+
41
+ let bestFolder = path
42
+ let bestLeanToolchain: FileUri | undefined
40
43
  while (true) {
41
- const leanToolchain = path.join('lean-toolchain');
42
- const lakefileLean = path.join('lakefile.lean');
43
- const lakefileToml = path.join('lakefile.toml');
44
+ const leanToolchain = path.join('lean-toolchain')
45
+ const lakefileLean = path.join('lakefile.lean')
46
+ const lakefileToml = path.join('lakefile.toml')
44
47
  if (await fileExists(leanToolchain.fsPath)) {
45
- bestFolder = path;
46
- bestLeanToolchain = leanToolchain;
47
- }
48
- else if (await isCoreLean4Directory(path)) {
49
- bestFolder = path;
50
- bestLeanToolchain = undefined;
48
+ bestFolder = path
49
+ bestLeanToolchain = leanToolchain
50
+ } else if (await isCoreLean4Directory(path)) {
51
+ bestFolder = path
52
+ bestLeanToolchain = undefined
51
53
  // Stop searching in case users accidentally created a lean-toolchain file above the core directory
52
- break;
53
- }
54
- else if (await fileExists(lakefileLean.fsPath)) {
55
- return { kind: 'LakefileWithoutToolchain', projectRootUri: path, lakefileUri: lakefileLean };
56
- }
57
- else if (await fileExists(lakefileToml.fsPath)) {
58
- return { kind: 'LakefileWithoutToolchain', projectRootUri: path, lakefileUri: lakefileToml };
54
+ break
55
+ } else if (await fileExists(lakefileLean.fsPath)) {
56
+ return { kind: 'LakefileWithoutToolchain', projectRootUri: path, lakefileUri: lakefileLean }
57
+ } else if (await fileExists(lakefileToml.fsPath)) {
58
+ return { kind: 'LakefileWithoutToolchain', projectRootUri: path, lakefileUri: lakefileToml }
59
59
  }
60
60
  if (isWorkspaceFolder(path)) {
61
61
  if (bestLeanToolchain === undefined) {
62
62
  // If we haven't found a toolchain yet, prefer the workspace folder as the project scope for the file,
63
63
  // but keep looking in case there is a lean-toolchain above the workspace folder
64
64
  // (New users sometimes accidentally open sub-folders of projects)
65
- bestFolder = path;
66
- }
67
- else {
65
+ bestFolder = path
66
+ } else {
68
67
  // Stop looking above the barrier if we have a toolchain. This is necessary for the nested lean-toolchain setup of core.
69
- break;
68
+ break
70
69
  }
71
70
  }
72
- const parent = path.join('..');
71
+ const parent = path.join('..')
73
72
  if (parent.equals(path)) {
74
73
  // no project file found.
75
- break;
74
+ break
76
75
  }
77
- path = parent;
76
+ path = parent
78
77
  }
79
- return { kind: 'Success', projectRootUri: bestFolder, toolchainUri: bestLeanToolchain };
78
+
79
+ return { kind: 'Success', projectRootUri: bestFolder, toolchainUri: bestLeanToolchain }
80
+ */
80
81
  }
81
82
  export async function findLeanProjectInfo(uri) {
82
83
  const info = await findLeanProjectRootInfo(uri);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lean4monaco",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "Monaco Editor support for the Lean 4 theorem prover.",
5
5
  "keywords": [
6
6
  "lean",
@@ -39,7 +39,10 @@
39
39
  "watch:copyfiles": "nodemon --watch ./src --exec \"npm run build:copyfiles\"",
40
40
  "build:copyfiles": "cd src && copyfiles \"**/*.json\" \"**/*.css\" \"**/*.ttf\" \"**/*.otf\" \"**/*.svg\" ../dist/",
41
41
  "build": "tsc && webpack && npm run build:copyfiles",
42
- "test": "npm run demo:setup && concurrently --hide 0 --kill-others \"npm start\" \"wait-on http://localhost:5173 && cypress run\" -n server,cypress -s command-cypress"
42
+ "test:bare": "wait-on http://localhost:5173 && cypress run",
43
+ "test": "npm run demo:setup && concurrently --hide 0 --kill-others \"npm start\" \"npm run test:bare\" -n server,cypress -s command-cypress",
44
+ "test:windows:bare": "wait-on http://localhost:5173 && CYPRESS_USER_AGENT_OS=\"Windows NT 10.0; Win64; x64\" cypress run --browser chromium",
45
+ "test:windows": "npm run demo:setup && concurrently --hide 0 --kill-others \"npm start\" \"npm run test:windows:bare\" -n server,cypress -s command-cypress"
43
46
  },
44
47
  "dependencies": {
45
48
  "@leanprover/infoview": "~0.8.5",