@lvce-editor/shared-process 0.12.0 → 0.12.1

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.
Files changed (102) hide show
  1. package/config/defaultKeyBindings.json +5 -0
  2. package/config/defaultSettings.json +4 -0
  3. package/extensions/builtin.language-basics-graphql/extension.json +1 -1
  4. package/extensions/builtin.language-basics-graphql/src/tokenizeGraphql.js +408 -4
  5. package/extensions/builtin.language-basics-html/src/tokenizeHtml.js +91 -3
  6. package/extensions/builtin.language-basics-javascript/src/tokenizeJavaScript.js +7 -0
  7. package/extensions/builtin.language-basics-json/extension.json +3 -1
  8. package/extensions/builtin.language-basics-jsx/README.md +14 -0
  9. package/extensions/builtin.language-basics-jsx/extension.json +13 -0
  10. package/extensions/builtin.language-basics-jsx/src/tokenizeJsx.js +648 -0
  11. package/extensions/builtin.language-basics-julia/src/tokenizeJulia.js +52 -1
  12. package/extensions/builtin.language-basics-markdown/src/tokenizeMarkdown.js +82 -2
  13. package/extensions/builtin.language-basics-mdx/README.md +14 -0
  14. package/extensions/builtin.language-basics-mdx/extension.json +12 -0
  15. package/extensions/builtin.language-basics-mdx/src/tokenizeMdx.js +395 -0
  16. package/extensions/builtin.language-basics-shellscript/src/tokenizeShellScript.js +22 -1
  17. package/extensions/builtin.language-basics-toml/src/tokenizeToml.js +29 -1
  18. package/extensions/builtin.language-basics-typescript/extension.json +1 -1
  19. package/extensions/builtin.language-basics-typescript/src/tokenizeTypeScript.js +128 -12
  20. package/extensions/builtin.language-basics-xml/extension.json +3 -2
  21. package/extensions/builtin.language-basics-xml/src/tokenizeXml.js +26 -3
  22. package/extensions/builtin.language-basics-yaml/src/tokenizeYaml.js +7 -1
  23. package/extensions/builtin.theme-atom-one-dark/color-theme.json +4 -0
  24. package/extensions/builtin.theme-cobalt2/color-theme.json +4 -0
  25. package/extensions/builtin.theme-gruvbox/color-theme.json +4 -0
  26. package/extensions/builtin.vscode-icons/icon-theme.json +40 -2
  27. package/extensions/builtin.vscode-icons/icons/file_type_bazel_ignore.svg +1 -0
  28. package/extensions/builtin.vscode-icons/icons/file_type_bazel_version.svg +1 -0
  29. package/extensions/builtin.vscode-icons/icons/file_type_eleventy.svg +1 -0
  30. package/extensions/builtin.vscode-icons/icons/file_type_eleventy2.svg +1 -0
  31. package/extensions/builtin.vscode-icons/icons/file_type_light_eleventy.svg +1 -0
  32. package/extensions/builtin.vscode-icons/icons/file_type_light_eleventy2.svg +1 -0
  33. package/extensions/builtin.vscode-icons/icons/file_type_light_rome.svg +1 -0
  34. package/extensions/builtin.vscode-icons/icons/file_type_light_tree.svg +1 -0
  35. package/extensions/builtin.vscode-icons/icons/file_type_mondoo.svg +1 -0
  36. package/extensions/builtin.vscode-icons/icons/file_type_nuxt.svg +1 -1
  37. package/extensions/builtin.vscode-icons/icons/file_type_rome.svg +1 -0
  38. package/extensions/builtin.vscode-icons/icons/file_type_sapphire_framework_cli.svg +1 -0
  39. package/extensions/builtin.vscode-icons/icons/file_type_shellcheck.svg +91 -0
  40. package/extensions/builtin.vscode-icons/icons/file_type_shuttle.svg +1 -0
  41. package/extensions/builtin.vscode-icons/icons/file_type_tree.svg +1 -0
  42. package/extensions/builtin.vscode-icons/icons/folder_type_nuxt.svg +1 -1
  43. package/extensions/builtin.vscode-icons/icons/folder_type_nuxt_opened.svg +1 -1
  44. package/package.json +7 -6
  45. package/src/parts/CleanStack/CleanStack.js +5 -0
  46. package/src/parts/Cli/Cli.js +5 -4
  47. package/src/parts/CliCommandType/CliCommandType.js +10 -0
  48. package/src/parts/CliInstall/CliInstall.js +3 -2
  49. package/src/parts/CliLink/CliLink.js +3 -2
  50. package/src/parts/CliList/CliList.js +3 -1
  51. package/src/parts/ClipBoard/ClipBoard.js +3 -2
  52. package/src/parts/ClipBoard/ClipBoardGnome.js +15 -31
  53. package/src/parts/CommandNotFoundError/CommandNotFoundError.js +9 -0
  54. package/src/parts/DesktopType/DesktopType.js +3 -0
  55. package/src/parts/Download/Download.js +1 -1
  56. package/src/parts/DownloadAndExtract/DownloadAndExtract.js +2 -2
  57. package/src/parts/Error/FileSystemError.js +1 -1
  58. package/src/parts/ErrorCodes/ErrorCodes.js +2 -0
  59. package/src/parts/ErrorHandling/ErrorHandling.js +4 -3
  60. package/src/parts/ExecCommand/ExecCommand.js +25 -0
  61. package/src/parts/ExecPromise/ExecPromise.js +4 -0
  62. package/src/parts/ExitCode/ExitCode.js +5 -0
  63. package/src/parts/ExportStatic/ExportStatic.js +2 -2
  64. package/src/parts/ExtensionHost/ExtensionHost.ipc.js +0 -1
  65. package/src/parts/ExtensionHost/ExtensionHost.js +1 -1
  66. package/src/parts/ExtensionHostIpc/ExtensionHostIpcWithChildProcess.js +3 -8
  67. package/src/parts/ExtensionHostIpc/ExtensionHostIpcWithWorker.js +3 -7
  68. package/src/parts/ExtensionInstallFromFile/ExtensionInstallFromFile.js +2 -5
  69. package/src/parts/ExtensionInstallFromGitHub/ExtensionInstallFromGitHub.js +1 -1
  70. package/src/parts/ExtensionInstallFromUrl/ExtensionInstallFromUrl.js +3 -3
  71. package/src/parts/ExtensionLink/ExtensionLink.js +19 -0
  72. package/src/parts/ExtensionManagement/ExtensionManagement.ipc.js +1 -1
  73. package/src/parts/ExtensionManagement/ExtensionManagementColorTheme.js +3 -2
  74. package/src/parts/ExtensionManagement/ExtensionManagementLanguages.js +7 -14
  75. package/src/parts/ExtensionManifest/ExtensionManifest.js +14 -4
  76. package/src/parts/ExtractZip/ExtractZip.js +1 -1
  77. package/src/parts/GetResponse/GetResponse.js +2 -1
  78. package/src/parts/GitLsFiles/GitLsFiles.ipc.js +2 -0
  79. package/src/parts/GitLsFiles/GitLsFiles.js +21 -5
  80. package/src/parts/Hash/Hash.js +7 -0
  81. package/src/parts/IpcChild/IpcChild.js +6 -0
  82. package/src/parts/IpcChildModule/IpcChildModule.js +12 -0
  83. package/src/parts/IpcChildType/IpcChildType.js +13 -0
  84. package/src/parts/IpcChildWithNodeForkedProcess/IpcChildWithNodeForkedProcess.js +19 -0
  85. package/src/parts/IpcChildWithNodeWorker/IpcChildWithNodeWorker.js +27 -0
  86. package/src/parts/MergeStacks/MergeStacks.js +19 -0
  87. package/src/parts/ModuleMap/ModuleMap.js +4 -1
  88. package/src/parts/NormalizeErrorLine/NormalizeErrorLine.js +9 -0
  89. package/src/parts/OutputChannel/OutputChannel.ipc.js +1 -1
  90. package/src/parts/ParentIpc/ParentIpc.js +6 -10
  91. package/src/parts/ParseInt/ParseInt.js +3 -0
  92. package/src/parts/Platform/Platform.js +16 -21
  93. package/src/parts/Preferences/Preferences.js +2 -1
  94. package/src/parts/PrettyError/PrettyError.js +12 -23
  95. package/src/parts/PrintPrettyError/PrintPrettyError.js +3 -0
  96. package/src/parts/Process/Process.js +2 -2
  97. package/src/parts/ProtocolType/ProtocolType.js +3 -0
  98. package/src/parts/RecentlyOpened/RecentlyOpened.js +1 -1
  99. package/src/parts/Stats/Stats.js +8 -11
  100. package/src/parts/SymLink/SymLink.js +2 -14
  101. package/src/parts/TextDocument/TextDocument.js +3 -1
  102. package/src/parts/VError/VError.js +5 -22
@@ -1,5 +1,5 @@
1
- import extract from 'extract-zip'
2
1
  import { mkdir } from 'node:fs/promises'
2
+ import extract from 'extract-zip'
3
3
  import VError from 'verror'
4
4
 
5
5
  export const extractZip = async ({ inFile, outDir }) => {
@@ -3,6 +3,7 @@ import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
3
3
  import * as JsonRpcErrorCode from '../JsonRpcErrorCode/JsonRpcErrorCode.js'
4
4
  import * as JsonRpcVersion from '../JsonRpcVersion/JsonRpcVersion.js'
5
5
  import * as PrettyError from '../PrettyError/PrettyError.js'
6
+ import * as PrintPrettyError from '../PrintPrettyError/PrintPrettyError.js'
6
7
  import { requiresSocket } from '../RequiresSocket/RequiresSocket.js'
7
8
 
8
9
  export const getResponse = async (message, handle) => {
@@ -40,7 +41,7 @@ export const getResponse = async (message, handle) => {
40
41
  }
41
42
  }
42
43
  const prettyError = PrettyError.prepare(error)
43
- PrettyError.print(prettyError, `[shared-process] `)
44
+ PrintPrettyError.printPrettyError(prettyError, `[shared-process] `)
44
45
  return {
45
46
  jsonrpc: JsonRpcVersion.Two,
46
47
  id: message.id,
@@ -4,4 +4,6 @@ export const name = 'GitLsFiles'
4
4
 
5
5
  export const Commands = {
6
6
  gitLsFiles: GitLsFiles.gitLsFiles,
7
+ gitLsFilesHash: GitLsFiles.gitLsFilesHash,
8
+ resolveGit: GitLsFiles.resolveGit,
7
9
  }
@@ -1,9 +1,25 @@
1
- import * as Exec from '../Exec/Exec.js'
1
+ import * as ExecCommand from '../ExecCommand/ExecCommand.js'
2
+ import * as Hash from '../Hash/Hash.js'
2
3
 
3
- export const gitLsFiles = async (cwd, limit) => {
4
- const { stdout, stderr } = await Exec.exec('git', ['ls-files'], {
4
+ export const gitLsFiles = async (gitPath, cwd, limit) => {
5
+ const { stdout, stderr } = await ExecCommand.execCommand(gitPath, ['ls-files'], {
5
6
  cwd,
6
7
  })
7
- // TODO limit stdout lines to given limit
8
- return stdout
8
+ const hash = Hash.fromString(stdout)
9
+ return {
10
+ stdout,
11
+ cacheId: hash,
12
+ }
13
+ }
14
+
15
+ export const gitLsFilesHash = async (gitPath, cwd, limit) => {
16
+ const hash = await ExecCommand.execCommandHash(gitPath, ['ls-files'], {
17
+ cwd,
18
+ })
19
+ return hash
20
+ }
21
+
22
+ export const resolveGit = async () => {
23
+ const bin = ExecCommand.execSync(`which git`)
24
+ return bin
9
25
  }
@@ -0,0 +1,7 @@
1
+ import * as NodeCrypto from 'node:crypto'
2
+
3
+ export const fromString = (content) => {
4
+ return NodeCrypto.createHash('sha1').update(content).digest('hex')
5
+ }
6
+
7
+ export const { createHash } = NodeCrypto
@@ -0,0 +1,6 @@
1
+ import * as IpcChildModule from '../IpcChildModule/IpcChildModule.js'
2
+
3
+ export const listen = async ({ method }) => {
4
+ const module = await IpcChildModule.getModule(method)
5
+ return module.listen()
6
+ }
@@ -0,0 +1,12 @@
1
+ import * as IpcChildType from '../IpcChildType/IpcChildType.js'
2
+
3
+ export const getModule = (method) => {
4
+ switch (method) {
5
+ case IpcChildType.NodeForkedProcess:
6
+ return import('../IpcChildWithNodeForkedProcess/IpcChildWithNodeForkedProcess.js')
7
+ case IpcChildType.NodeWorker:
8
+ return import('../IpcChildWithNodeWorker/IpcChildWithNodeWorker.js')
9
+ default:
10
+ throw new Error('unexpected ipc type')
11
+ }
12
+ }
@@ -0,0 +1,13 @@
1
+ export const NodeWorker = 1
2
+ export const NodeForkedProcess = 2
3
+
4
+ export const Auto = () => {
5
+ const { argv } = process
6
+ if (argv.includes('--ipc-type=node-worker')) {
7
+ return NodeWorker
8
+ }
9
+ if (argv.includes('--ipc-type=node-forked-process')) {
10
+ return NodeForkedProcess
11
+ }
12
+ throw new Error(`[shared-process] unknown ipc type`)
13
+ }
@@ -0,0 +1,19 @@
1
+ export const listen = async () => {
2
+ return process
3
+ }
4
+
5
+ export const wrap = (process) => {
6
+ return {
7
+ process,
8
+ on(event, listener) {
9
+ this.process.on(event, listener)
10
+ },
11
+ off(event, listener) {
12
+ this.process.off(event, listener)
13
+ },
14
+ send(message) {
15
+ this.process.send(message)
16
+ },
17
+ dispose() {},
18
+ }
19
+ }
@@ -0,0 +1,27 @@
1
+ import { parentPort } from 'node:worker_threads'
2
+
3
+ export const listen = async () => {
4
+ if (!parentPort) {
5
+ throw new Error('parentPort is required')
6
+ }
7
+ parentPort.postMessage('ready')
8
+ return parentPort
9
+ }
10
+
11
+ export const wrap = (parentPort) => {
12
+ return {
13
+ parentPort,
14
+ on(event, listener) {
15
+ this.parentPort.on(event, listener)
16
+ },
17
+ off(event, listener) {
18
+ this.parentPort.off(event, listener)
19
+ },
20
+ send(message) {
21
+ this.parentPort.postMessage(message)
22
+ },
23
+ dispose() {
24
+ this.parentPort.close()
25
+ },
26
+ }
27
+ }
@@ -0,0 +1,19 @@
1
+ import * as NormalizeErrorLine from '../NormalizeErrorLine/NormalizeErrorLine.js'
2
+
3
+ export const mergeStacks = (parent, child) => {
4
+ if (!child) {
5
+ return parent
6
+ }
7
+ const parentNewLineIndex = parent.indexOf('\n')
8
+ const childNewLineIndex = child.indexOf('\n')
9
+ if (childNewLineIndex === -1) {
10
+ return parent
11
+ }
12
+ const parentFirstLine = parent.slice(0, parentNewLineIndex)
13
+ const childRest = child.slice(childNewLineIndex)
14
+ const childFirstLine = NormalizeErrorLine.normalizeLine(child.slice(0, childNewLineIndex))
15
+ if (parentFirstLine.includes(childFirstLine)) {
16
+ return parentFirstLine + childRest
17
+ }
18
+ return child
19
+ }
@@ -1,3 +1,4 @@
1
+ import { CommandNotFoundError } from '../CommandNotFoundError/CommandNotFoundError.js'
1
2
  import * as ModuleId from '../ModuleId/ModuleId.js'
2
3
 
3
4
  export const getModuleId = (commandId) => {
@@ -93,6 +94,8 @@ export const getModuleId = (commandId) => {
93
94
  case 'FileSystem.writeFile':
94
95
  return ModuleId.FileSystem
95
96
  case 'GitLsFiles.gitLsFiles':
97
+ case 'GitLsFiles.gitLsFilesHash':
98
+ case 'GitLsFiles.resolveGit':
96
99
  return ModuleId.GitLsFiles
97
100
  case 'Native.openFolder':
98
101
  return ModuleId.Native
@@ -137,6 +140,6 @@ export const getModuleId = (commandId) => {
137
140
  case 'Workspace.resolveRoot':
138
141
  return ModuleId.Workspace
139
142
  default:
140
- throw new Error(`command ${commandId} not found`)
143
+ throw new CommandNotFoundError(commandId)
141
144
  }
142
145
  }
@@ -0,0 +1,9 @@
1
+ export const normalizeLine = (line) => {
2
+ if (line.startsWith('Error: ')) {
3
+ return line.slice(`Error: `.length)
4
+ }
5
+ if (line.startsWith('VError: ')) {
6
+ return line.slice(`VError: `.length)
7
+ }
8
+ return line
9
+ }
@@ -1,7 +1,7 @@
1
1
  import * as Assert from '../Assert/Assert.js'
2
2
  import * as Command from '../Command/Command.js'
3
- import * as OutputChannel from './OutputChannel.js'
4
3
  import * as JsonRpcVersion from '../JsonRpcVersion/JsonRpcVersion.js'
4
+ import * as OutputChannel from './OutputChannel.js'
5
5
 
6
6
  export const state = {
7
7
  outputChannels: Object.create(null),
@@ -8,7 +8,7 @@ import * as ExtensionHostHelperProcessIpc from '../ExtensionHostHelperProcessIpc
8
8
  import * as ExtensionHostIpc from '../ExtensionHostIpc/ExtensionHostIpc.js'
9
9
  import * as ExtensionHostRpc from '../ExtensionHostRpc/ExtensionHostRpc.js'
10
10
  import * as GetResponse from '../GetResponse/GetResponse.js'
11
-
11
+ import * as ProtocolType from '../ProtocolType/ProtocolType.js'
12
12
  // TODO add tests for this
13
13
 
14
14
  // TODO handle structure: one shared process multiple extension hosts
@@ -42,17 +42,13 @@ const handleWebSocketSharedProcess = (message, handle) => {
42
42
  }
43
43
  console.info('[info shared process: handle error]', error)
44
44
  })
45
- Command.execute(
46
- /* WebSocketServer.handleUpgrade */ 'WebSocketServer.handleUpgrade',
47
- /* message */ message,
48
- /* handle */ handle
49
- )
45
+ Command.execute(/* WebSocketServer.handleUpgrade */ 'WebSocketServer.handleUpgrade', /* message */ message, /* handle */ handle)
50
46
  }
51
47
 
52
48
  // TODO lazyload modules for spawning extension host, they are only needed later
53
49
  const handleWebSocketExtensionHost = async (message, handle) => {
54
50
  // console.log('[shared-process] received extension host websocket', message)
55
- const ipc = ExtensionHostIpc.create()
51
+ const ipc = await ExtensionHostIpc.create()
56
52
  console.info('[sharedprocess] creating extension ipc')
57
53
  const rpc = await ExtensionHostRpc.create(ipc, handle)
58
54
  console.info('[sharedprocess] created extension host rpc')
@@ -77,11 +73,11 @@ const handleWebSocket = (message, handle) => {
77
73
  throw new VError('missing sec websocket protocol header')
78
74
  }
79
75
  switch (protocol) {
80
- case 'lvce.shared-process':
76
+ case ProtocolType.SharedProcess:
81
77
  return handleWebSocketSharedProcess(message, handle)
82
- case 'lvce.extension-host':
78
+ case ProtocolType.ExtensionHost:
83
79
  return handleWebSocketExtensionHost(message, handle)
84
- case 'lvce.extension-host-helper-process':
80
+ case ProtocolType.ExtensionHostHelperProcess:
85
81
  return handleWebSocketExtensionHostHelperProcess(message, handle)
86
82
  default:
87
83
  console.warn(`unsupported sec-websocket-procotol ${protocol}`)
@@ -0,0 +1,3 @@
1
+ export const parseInt = (string) => {
2
+ return Number.parseInt(string, 10)
3
+ }
@@ -1,9 +1,10 @@
1
- import { extensionHostPath } from '@lvce-editor/extension-host'
2
1
  import { homedir, tmpdir } from 'node:os'
3
- import { dirname, join, resolve, sep } from 'node:path'
4
- import { fileURLToPath, pathToFileURL } from 'node:url'
2
+ import { join, resolve, sep } from 'node:path'
3
+ import { pathToFileURL } from 'node:url'
5
4
  import { xdgCache, xdgConfig, xdgData, xdgState } from 'xdg-basedir'
5
+ import * as DesktopType from '../DesktopType/DesktopType.js'
6
6
  import * as Path from '../Path/Path.js'
7
+ import * as Process from '../Process/Process.js'
7
8
  import * as Root from '../Root/Root.js'
8
9
 
9
10
  const { env, platform } = process
@@ -24,8 +25,6 @@ export const homeDir = isWindows ? '' : homedir()
24
25
 
25
26
  export const appDir = Root.root
26
27
 
27
- const __dirname = dirname(fileURLToPath(import.meta.url))
28
-
29
28
  export const getExtensionsPath = () => {
30
29
  return Path.join(dataDir, 'extensions')
31
30
  }
@@ -55,32 +54,27 @@ export const getChromeExtensionsPath = () => {
55
54
  }
56
55
 
57
56
  export const getMarketplaceUrl = () => {
58
- return (
59
- env.LVCE_MARKETPLACE_URL || 'https://marketplace.22e924c84de072d4b25b.com'
60
- )
57
+ return env.LVCE_MARKETPLACE_URL || 'https://marketplace.22e924c84de072d4b25b.com'
61
58
  }
62
59
 
63
60
  export const getDesktop = () => {
64
61
  const { ORIGINAL_XDG_CURRENT_DESKTOP, XDG_CURRENT_DESKTOP } = env
65
- if (
66
- ORIGINAL_XDG_CURRENT_DESKTOP &&
67
- ORIGINAL_XDG_CURRENT_DESKTOP !== 'undefined'
68
- ) {
62
+ if (ORIGINAL_XDG_CURRENT_DESKTOP && ORIGINAL_XDG_CURRENT_DESKTOP !== 'undefined') {
69
63
  if (ORIGINAL_XDG_CURRENT_DESKTOP === 'ubuntu:GNOME') {
70
- return 'gnome'
64
+ return DesktopType.Gnome
71
65
  }
72
66
  return ORIGINAL_XDG_CURRENT_DESKTOP
73
67
  }
74
68
  if (XDG_CURRENT_DESKTOP) {
75
69
  if (XDG_CURRENT_DESKTOP === 'ubuntu:GNOME') {
76
- return 'gnome'
70
+ return DesktopType.Gnome
77
71
  }
78
72
  return XDG_CURRENT_DESKTOP
79
73
  }
80
74
  if (isWindows) {
81
- return 'windows'
75
+ return DesktopType.Windows
82
76
  }
83
- return ''
77
+ return DesktopType.Unknown
84
78
  }
85
79
 
86
80
  export const getPathSeparator = () => {
@@ -99,7 +93,10 @@ export const getUserSettingsPath = () => {
99
93
  return Path.join(configDir, 'settings.json')
100
94
  }
101
95
 
102
- export const getExtensionHostPath = () => {
96
+ export const getExtensionHostPath = async () => {
97
+ const { extensionHostPath } = await import(
98
+ '@lvce-editor/extension-host'
99
+ )
103
100
  return extensionHostPath
104
101
  }
105
102
 
@@ -125,16 +122,14 @@ export const setEnvironmentVariables = (variables) => {
125
122
 
126
123
  export const getTestPath = () => {
127
124
  if (env.TEST_PATH) {
128
- const testPath =
129
- '/remote' +
130
- pathToFileURL(Path.join(process.cwd(), env.TEST_PATH)).toString().slice(7)
125
+ const testPath = '/remote' + pathToFileURL(Path.join(process.cwd(), env.TEST_PATH)).toString().slice(7)
131
126
  return testPath
132
127
  }
133
128
  return '/packages/extension-host-worker-tests'
134
129
  }
135
130
 
136
131
  export const getNodePath = () => {
137
- return process.argv[0]
132
+ return Process.argv[0]
138
133
  }
139
134
 
140
135
  export const getTmpDir = () => {
@@ -1,6 +1,7 @@
1
1
  import VError from 'verror'
2
2
  import * as JsonFile from '../JsonFile/JsonFile.js'
3
3
  import * as Platform from '../Platform/Platform.js'
4
+ import * as Process from '../Process/Process.js'
4
5
 
5
6
  // TODO need jsonc parser for settings with comments
6
7
 
@@ -38,7 +39,7 @@ export const getDefaultPreferences = async () => {
38
39
  // -> on idle check preferences
39
40
 
40
41
  const getOverrides = () => {
41
- const argvSliced = process.argv.slice(2)
42
+ const argvSliced = Process.argv.slice(2)
42
43
  const overrides = {}
43
44
  for (const argv of argvSliced) {
44
45
  if (argv.startsWith('--theme=')) {
@@ -1,9 +1,10 @@
1
1
  import { codeFrameColumns } from '@babel/code-frame'
2
- import cleanStack from 'clean-stack'
3
2
  import { LinesAndColumns } from 'lines-and-columns'
4
3
  import { readFileSync } from 'node:fs'
5
4
  import { fileURLToPath } from 'node:url'
5
+ import * as CleanStack from '../CleanStack/CleanStack.js'
6
6
  import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
7
+ import * as JoinLines from '../JoinLines/JoinLines.js'
7
8
  import * as Json from '../Json/Json.js'
8
9
  import * as SplitLines from '../SplitLines/SplitLines.js'
9
10
 
@@ -14,11 +15,10 @@ const getActualPath = (fileUri) => {
14
15
  return fileUri
15
16
  }
16
17
 
17
- const RE_MODULE_NOT_FOUND_STACK =
18
- /Cannot find package '([^']+)' imported from (.+)$/
18
+ const RE_MODULE_NOT_FOUND_STACK = /Cannot find package '([^']+)' imported from (.+)$/
19
19
 
20
20
  const prepareModuleNotFoundError = (error) => {
21
- const message = error.message
21
+ const { message } = error
22
22
  const match = message.match(RE_MODULE_NOT_FOUND_STACK)
23
23
  if (!match) {
24
24
  return {
@@ -32,7 +32,7 @@ const prepareModuleNotFoundError = (error) => {
32
32
  const rawLines = readFileSync(importedFrom, 'utf-8')
33
33
  let line = 0
34
34
  let column = 0
35
- const splittedLines = rawLines.split('\n')
35
+ const splittedLines = SplitLines.splitLines(rawLines)
36
36
  for (let i = 0; i < splittedLines.length; i++) {
37
37
  const splittedLine = splittedLines[i]
38
38
  const index = splittedLine.indexOf(notFoundModule)
@@ -50,12 +50,8 @@ const prepareModuleNotFoundError = (error) => {
50
50
  }
51
51
  const codeFrame = codeFrameColumns(rawLines, location)
52
52
  const stackLines = SplitLines.splitLines(error.stack)
53
- const newStackLines = [
54
- stackLines[0],
55
- ` at ${importedFrom}:${line}:${column}`,
56
- ...stackLines.slice(1),
57
- ]
58
- const newStack = newStackLines.join('\n')
53
+ const newStackLines = [stackLines[0], ` at ${importedFrom}:${line}:${column}`, ...stackLines.slice(1)]
54
+ const newStack = JoinLines.joinLines(newStackLines)
59
55
  return {
60
56
  message,
61
57
  stack: newStack,
@@ -67,14 +63,14 @@ export const prepare = (error) => {
67
63
  if (error && error.code === ErrorCodes.ERR_MODULE_NOT_FOUND) {
68
64
  return prepareModuleNotFoundError(error)
69
65
  }
70
- const message = error.message
66
+ const { message } = error
71
67
  if (error && error.cause) {
72
68
  const cause = error.cause()
73
69
  if (cause) {
74
70
  error = cause
75
71
  }
76
72
  }
77
- const cleanedStack = cleanStack(error.stack)
73
+ const cleanedStack = CleanStack.cleanStack(error.stack)
78
74
  const lines = SplitLines.splitLines(cleanedStack)
79
75
  const file = lines[1]
80
76
  let codeFrame = ''
@@ -99,7 +95,7 @@ export const prepare = (error) => {
99
95
  codeFrame = codeFrameColumns(rawLines, location)
100
96
  }
101
97
  }
102
- const relevantStack = lines.slice(1).join('\n')
98
+ const relevantStack = JoinLines.joinLines(lines.slice(1))
103
99
  return {
104
100
  message,
105
101
  stack: relevantStack,
@@ -121,10 +117,9 @@ export const prepareJsonError = (json, property, message) => {
121
117
  }
122
118
  if (index !== -1) {
123
119
  const lines = new LinesAndColumns(string)
124
- const location = lines.locationForIndex(
125
- index + stringifiedPropertyName.length + 1
126
- )
120
+ const location = lines.locationForIndex(index + stringifiedPropertyName.length + 1)
127
121
  const codeFrame = codeFrameColumns(string, {
122
+ // @ts-ignore
128
123
  start: { line: location.line + 1, column: location.column + 1 },
129
124
  })
130
125
  jsonError.codeFrame = codeFrame
@@ -132,9 +127,3 @@ export const prepareJsonError = (json, property, message) => {
132
127
  // jsonError.stack = `${bottomMessage}\n at ${filePath}`
133
128
  return jsonError
134
129
  }
135
-
136
- export const print = (prettyError, prefix = '') => {
137
- console.error(
138
- `${prefix}Error: ${prettyError.message}\n\n${prettyError.codeFrame}\n\n${prettyError.stack}`
139
- )
140
- }
@@ -0,0 +1,3 @@
1
+ export const printPrettyError = (prettyError, prefix = '') => {
2
+ console.error(`${prefix}Error: ${prettyError.message}\n\n${prettyError.codeFrame}\n\n${prettyError.stack}`)
3
+ }
@@ -14,7 +14,7 @@ export const setExitCode = (exitCode) => {
14
14
  process.exitCode = exitCode
15
15
  }
16
16
 
17
- export const argv = process.argv
17
+ export const { argv } = process
18
18
 
19
19
  export const cwd = () => {
20
20
  return process.cwd()
@@ -28,4 +28,4 @@ export const isConnected = () => {
28
28
  return process.connected
29
29
  }
30
30
 
31
- export const platform = process.platform
31
+ export const { platform } = process
@@ -0,0 +1,3 @@
1
+ export const SharedProcess = 'lvce.shared-process'
2
+ export const ExtensionHost = 'lvce.extension-host'
3
+ export const ExtensionHostHelperProcess = 'lvce.extension-host-helper-process'
@@ -1,4 +1,4 @@
1
- import { dirname } from 'path'
1
+ import { dirname } from 'node:path'
2
2
  import VError from 'verror'
3
3
  import * as Assert from '../Assert/Assert.js'
4
4
  import { FileNotFoundError } from '../Error/FileNotFoundError.js'
@@ -2,6 +2,7 @@
2
2
 
3
3
  import * as Exec from '../Exec/Exec.js'
4
4
  import * as SplitLines from '../SplitLines/SplitLines.js'
5
+ import * as ParseInt from '../ParseInt/ParseInt.js'
5
6
 
6
7
  const PID_CMD = /^\s*(\d+)\s+(\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)\s+(.+)$/
7
8
 
@@ -9,11 +10,11 @@ const parsePsOutputLine = (line) => {
9
10
  const matches = PID_CMD.exec(line.trim())
10
11
  if (matches && matches.length === 6) {
11
12
  return {
12
- pid: Number.parseInt(matches[1]),
13
- ppid: Number.parseInt(matches[2]),
13
+ pid: ParseInt.parseInt(matches[1]),
14
+ ppid: ParseInt.parseInt(matches[2]),
14
15
  cwd: matches[5],
15
- load: Number.parseInt(matches[3]),
16
- mem: Number.parseInt(matches[4]),
16
+ load: ParseInt.parseInt(matches[3]),
17
+ mem: ParseInt.parseInt(matches[4]),
17
18
  }
18
19
  }
19
20
  }
@@ -23,13 +24,9 @@ const parsePsOutput = (stdout, rootPid) => {
23
24
  }
24
25
 
25
26
  const getPsOutput = async (rootPid) => {
26
- const { stdout } = await Exec.exec(
27
- 'ps',
28
- ['-g', `${rootPid}`, '-a', '-o', 'pid=,ppid=,pcpu=,pmem=,command='],
29
- {
30
- shell: true,
31
- }
32
- )
27
+ const { stdout } = await Exec.exec('ps', ['-g', `${rootPid}`, '-a', '-o', 'pid=,ppid=,pcpu=,pmem=,command='], {
28
+ shell: true,
29
+ })
33
30
  return stdout
34
31
  }
35
32
 
@@ -1,17 +1,5 @@
1
- import { mkdir, symlink } from 'node:fs/promises'
2
- import { dirname } from 'node:path'
3
- import { FileSystemError } from '../Error/FileSystemError.js'
4
-
5
- // TODO maybe move this to FileSystem module
1
+ import symlinkDir from 'symlink-dir'
6
2
 
7
3
  export const createSymLink = async (target, path) => {
8
- try {
9
- await mkdir(dirname(path), { recursive: true })
10
- await symlink(target, path)
11
- } catch (error) {
12
- throw new FileSystemError(
13
- error,
14
- `Failed to create symbolic link from ${target} to ${path}`
15
- )
16
- }
4
+ await symlinkDir(target, path)
17
5
  }
@@ -1,3 +1,5 @@
1
+ import * as JoinLines from '../JoinLines/JoinLines.js'
2
+
1
3
  export const state = {
2
4
  textDocuments: Object.create(null),
3
5
  /** @type{any[]} */
@@ -29,7 +31,7 @@ export const applyEdit = (socket, textDocument, documentEdits) => {
29
31
  }
30
32
 
31
33
  export const getText = (textDocument) => {
32
- return textDocument.lines.join('\n')
34
+ return JoinLines.joinLines(textDocument.lines)
33
35
  }
34
36
 
35
37
  export const onChange = (listener) => {
@@ -1,38 +1,21 @@
1
+ import * as MergeStacks from '../MergeStacks/MergeStacks.js'
2
+ import * as NormalizeErrorLine from '../NormalizeErrorLine/NormalizeErrorLine.js'
3
+
1
4
  const getCombinedMessage = (error, message) => {
2
- let stringifiedError = `${error}`
3
- if (stringifiedError.startsWith('Error: ')) {
4
- stringifiedError = stringifiedError.slice(`Error: `.length)
5
- } else if (stringifiedError.startsWith('VError: ')) {
6
- stringifiedError = stringifiedError.slice(`VError: `.length)
7
- }
5
+ const stringifiedError = NormalizeErrorLine.normalizeLine(`${error}`)
8
6
  if (message) {
9
7
  return `${message}: ${stringifiedError}`
10
8
  }
11
9
  return stringifiedError
12
10
  }
13
11
 
14
- const mergeStacks = (parent, child) => {
15
- if (!child) {
16
- return parent
17
- }
18
- const parentNewLineIndex = parent.indexOf('\n')
19
- const childNewLineIndex = child.indexOf('\n')
20
- const parentFirstLine = parent.slice(0, parentNewLineIndex)
21
- const childRest = child.slice(childNewLineIndex)
22
- const childFirstLine = child.slice(0, childNewLineIndex)
23
- if (parentFirstLine.includes(childFirstLine)) {
24
- return parentFirstLine + childRest
25
- }
26
- return child
27
- }
28
-
29
12
  export class VError extends Error {
30
13
  constructor(error, message) {
31
14
  const combinedMessage = getCombinedMessage(error, message)
32
15
  super(combinedMessage)
33
16
  this.name = 'VError'
34
17
  if (error instanceof Error) {
35
- this.stack = mergeStacks(this.stack, error.stack)
18
+ this.stack = MergeStacks.mergeStacks(this.stack, error.stack)
36
19
  }
37
20
  if (error.codeFrame) {
38
21
  this.codeFrame = error.codeFrame