@lvce-editor/shared-process 0.0.27 → 0.0.30

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 (70) hide show
  1. package/config/builtinCommands.json +103 -87
  2. package/config/defaultKeyBindings.json +18 -18
  3. package/config/defaultSettings.json +3 -1
  4. package/index.js +2 -2
  5. package/package.json +13 -10
  6. package/src/parts/Assert/Assert.js +12 -5
  7. package/src/parts/ChildProcess/ChildProcessWithFork.js +19 -0
  8. package/src/parts/ClipBoard/ClipBoard.ipc.js +3 -4
  9. package/src/parts/Command/Command.js +30 -17
  10. package/src/parts/Credentials/Credentials.ipc.js +6 -7
  11. package/src/parts/Developer/Developer.ipc.js +10 -17
  12. package/src/parts/Electron/Electron.ipc.js +15 -16
  13. package/src/parts/Electron/Electron.js +43 -34
  14. package/src/parts/ExtensionHost/ExtensionHost.ipc.js +15 -72
  15. package/src/parts/ExtensionHost/ExtensionHost.js +59 -138
  16. package/src/parts/ExtensionHostIpc/ExtensionHostIpc.js +5 -0
  17. package/src/parts/ExtensionHostIpc/ExtensionHostIpcWithChildProcess.js +57 -0
  18. package/src/parts/ExtensionHostIpc/ExtensionHostIpcWithWorker.js +38 -0
  19. package/src/parts/ExtensionHostRpc/ExtensionHostRpc.js +82 -0
  20. package/src/parts/ExtensionManagement/ExtensionManagement.ipc.js +16 -8
  21. package/src/parts/ExtensionManagement/ExtensionManagement.js +5 -2
  22. package/src/parts/{ExtensionHost/ExtensionHostColorTheme.js → ExtensionManagement/ExtensionManagementColorTheme.js} +1 -1
  23. package/src/parts/{ExtensionHost/ExtensionHostIconTheme.js → ExtensionManagement/ExtensionManagementIconTheme.js} +1 -1
  24. package/src/parts/{ExtensionHost/ExtensionHostLanguages.js → ExtensionManagement/ExtensionManagementLanguages.js} +1 -1
  25. package/src/parts/FileSystem/FileSystem.ipc.js +14 -15
  26. package/src/parts/FileSystem/FileSystem.js +56 -1
  27. package/src/parts/JsonRpc/JsonRpc.js +2 -2
  28. package/src/parts/Native/Native.ipc.js +2 -3
  29. package/src/parts/OutputChannel/OutputChannel.ipc.js +16 -19
  30. package/src/parts/ParentIpc/ParentIpc.js +93 -44
  31. package/src/parts/Platform/Platform.ipc.js +15 -17
  32. package/src/parts/Platform/Platform.js +1 -1
  33. package/src/parts/Preferences/Preferences.ipc.js +2 -3
  34. package/src/parts/PrettyError/PrettyError.js +5 -2
  35. package/src/parts/Process/Process.ipc.js +3 -4
  36. package/src/parts/RequiresSocket/RequiresSocket.js +6 -5
  37. package/src/parts/Search/Search.ipc.js +2 -3
  38. package/src/parts/SearchFile/SearchFile.ipc.js +2 -3
  39. package/src/parts/Stats/Stats.js +5 -5
  40. package/src/parts/Terminal/Terminal.ipc.js +9 -9
  41. package/src/parts/Terminal/Terminal.js +1 -1
  42. package/src/parts/TextDocument/TextDocument.ipc.js +2 -3
  43. package/src/parts/Timeout/Timeout.js +7 -0
  44. package/src/parts/WebSocketServer/WebSocketServer.ipc.js +2 -3
  45. package/src/parts/Workspace/Workspace.ipc.js +3 -4
  46. package/src/sharedProcessMain.js +13 -9
  47. package/src/parts/Extension/Extension.js +0 -7
  48. package/src/parts/ExtensionHost/ExtensionHostBraceCompletion.js +0 -14
  49. package/src/parts/ExtensionHost/ExtensionHostClosingTag.js +0 -14
  50. package/src/parts/ExtensionHost/ExtensionHostCommand.js +0 -19
  51. package/src/parts/ExtensionHost/ExtensionHostCompletion.js +0 -12
  52. package/src/parts/ExtensionHost/ExtensionHostDefinition.js +0 -12
  53. package/src/parts/ExtensionHost/ExtensionHostDiagnostic.js +0 -7
  54. package/src/parts/ExtensionHost/ExtensionHostFileSystem.js +0 -23
  55. package/src/parts/ExtensionHost/ExtensionHostFormatting.js +0 -4
  56. package/src/parts/ExtensionHost/ExtensionHostHover.js +0 -12
  57. package/src/parts/ExtensionHost/ExtensionHostImplementation.js +0 -12
  58. package/src/parts/ExtensionHost/ExtensionHostManagement.js +0 -26
  59. package/src/parts/ExtensionHost/ExtensionHostOutput.js +0 -3
  60. package/src/parts/ExtensionHost/ExtensionHostQuickPick.js +0 -6
  61. package/src/parts/ExtensionHost/ExtensionHostReference.js +0 -12
  62. package/src/parts/ExtensionHost/ExtensionHostRename.js +0 -27
  63. package/src/parts/ExtensionHost/ExtensionHostSemanticTokens.js +0 -10
  64. package/src/parts/ExtensionHost/ExtensionHostSourceControl.js +0 -15
  65. package/src/parts/ExtensionHost/ExtensionHostStats.js +0 -3
  66. package/src/parts/ExtensionHost/ExtensionHostStatusBar.js +0 -7
  67. package/src/parts/ExtensionHost/ExtensionHostTabCompletion.js +0 -12
  68. package/src/parts/ExtensionHost/ExtensionHostTextDocument.js +0 -35
  69. package/src/parts/ExtensionHost/ExtensionHostTypeDefinition.js +0 -12
  70. package/src/parts/ExtensionHost/ExtensionHostWorkspace.js +0 -3
@@ -3,14 +3,14 @@ import * as Command from '../Command/Command.js'
3
3
  import * as OutputChannel from './OutputChannel.js'
4
4
 
5
5
  export const state = {
6
- outputChannels: Object.create(null)
6
+ outputChannels: Object.create(null),
7
7
  }
8
8
 
9
9
  const open = (socket, id, path) => {
10
- console.log({path})
10
+ console.log({ path })
11
11
  Assert.object(socket)
12
12
  // Assert.string(id)
13
- Assert.string(path )
13
+ Assert.string(path)
14
14
  if (!socket) {
15
15
  console.warn('socket not available')
16
16
  return
@@ -20,22 +20,19 @@ const open = (socket, id, path) => {
20
20
  }
21
21
  const onData = (data) => {
22
22
  console.log('send data', data)
23
- socket.send(
24
- {
25
- jsonrpc: '2.0',
26
- method: 2133,
27
- params: ['Output', 'handleData', data],
28
- }
29
- )
23
+ socket.send({
24
+ jsonrpc: '2.0',
25
+ method: 2133,
26
+ params: ['Output', 'handleData', data],
27
+ })
30
28
  }
31
29
  const onError = (error) => {
32
30
  console.info(`[shared process] output channel error: ${error}`)
33
- socket.send(
34
- {
35
- jsonrpc: '2.0',
36
- method: 2133,
37
- params: ['Output', 'handleError', error],
38
- })
31
+ socket.send({
32
+ jsonrpc: '2.0',
33
+ method: 2133,
34
+ params: ['Output', 'handleError', error],
35
+ })
39
36
  }
40
37
  state.outputChannels[id] = OutputChannel.open(path, onData, onError)
41
38
  }
@@ -45,7 +42,7 @@ const close = (socket, id) => {
45
42
  delete state.outputChannels[id]
46
43
  }
47
44
 
48
- export const __initialize__ = () => {
49
- Command.register('OutputChannel.open', open)
50
- Command.register('OutputChannel.close', close)
45
+ export const Commands = {
46
+ 'OutputChannel.open': open,
47
+ 'OutputChannel.close': close,
51
48
  }
@@ -1,10 +1,13 @@
1
1
  import { MessagePort, parentPort } from 'node:worker_threads'
2
+ import VError from 'verror'
2
3
  import * as Callback from '../Callback/Callback.js'
3
4
  import * as Command from '../Command/Command.js'
4
5
  import * as Debug from '../Debug/Debug.js'
5
6
  import * as Error from '../Error/Error.js'
6
7
  import { requiresSocket } from '../RequiresSocket/RequiresSocket.js'
7
-
8
+ import * as Platform from '../Platform/Platform.js'
9
+ import * as ExtensionHostIpc from '../ExtensionHostIpc/ExtensionHostIpc.js'
10
+ import * as ExtensionHostRpc from '../ExtensionHostRpc/ExtensionHostRpc.js'
8
11
  // TODO add tests for this
9
12
 
10
13
  // TODO handle structure: one shared process multiple extension hosts
@@ -30,53 +33,99 @@ export const electronSend = (message) => {
30
33
  }
31
34
  }
32
35
 
33
- const handleMessageFromParentProcess = async (message, handle) => {
34
- if (handle) {
35
- handle.on('error', (error) => {
36
- if (error && error.code === 'ECONNRESET') {
37
- return
38
- }
39
- console.info('[info shared process: handle error]', error)
40
- })
41
- Command.execute(
42
- /* WebSocketServer.handleUpgrade */ 5621,
43
- /* message */ message,
44
- /* handle */ handle
45
- )
46
- } else if (message.result) {
47
- Callback.resolve(message.id, message.result)
48
- } else if (message.method) {
49
- if (message.id) {
50
- try {
51
- const result = requiresSocket(message.method)
52
- ? await Command.invoke(message.method, handle, ...message.params)
53
- : await Command.invoke(message.method, ...message.params)
54
- electronSend({
55
- jsonrpc: '2.0',
56
- id: message.id,
57
- result: result ?? null,
58
- })
59
- } catch (error) {
60
- console.error('[shared process] command failed to execute')
61
- console.error(error)
62
- electronSend({
63
- jsonrpc: '2.0',
64
- code: /* ExpectedError */ -32000,
65
- id: message.id,
66
- error: 'ExpectedError',
67
- // @ts-ignore
68
- data: error.toString(),
69
- })
70
- }
71
- } else {
72
- // TODO handle error
73
- Command.execute(message.method, null, ...message.params)
36
+ const handleWebSocketSharedProcess = (message, handle) => {
37
+ // TODO when it is an extension host websocket, spawn extension host
38
+ handle.on('error', (error) => {
39
+ if (error && error.code === 'ECONNRESET') {
40
+ return
41
+ }
42
+ console.info('[info shared process: handle error]', error)
43
+ })
44
+ Command.execute(
45
+ /* WebSocketServer.handleUpgrade */ 5621,
46
+ /* message */ message,
47
+ /* handle */ handle
48
+ )
49
+ }
50
+
51
+ // TODO lazyload modules for spawning extension host, they are only needed later
52
+ const handleWebSocketExtensionHost = async (message, handle) => {
53
+ // console.log('[shared-process] received extension host websocket', message)
54
+ const ipc = ExtensionHostIpc.create()
55
+ console.info('[sharedprocess] creating extension ipc')
56
+ const rpc = await ExtensionHostRpc.create(ipc, handle)
57
+ console.info('[sharedprocess] created extension host rpc')
58
+ ipc._process.send(message, handle)
59
+ // rpc.send(message)
60
+ // console.log('spawned extension host')
61
+ // console.log(rpc)
62
+ }
63
+
64
+ const handleWebSocket = (message, handle) => {
65
+ const headers = message.headers
66
+ if (!headers) {
67
+ throw new VError('missing websocket headers')
68
+ }
69
+ const protocol = headers['sec-websocket-protocol']
70
+ if (!protocol) {
71
+ throw new VError('missing sec websocket protocol header')
72
+ }
73
+ switch (protocol) {
74
+ case 'lvce.shared-process':
75
+ return handleWebSocketSharedProcess(message, handle)
76
+ case 'lvce.extension-host':
77
+ return handleWebSocketExtensionHost(message, handle)
78
+ default:
79
+ throw new VError(`unsupported sec-websocket-procotol ${protocol}`)
80
+ }
81
+ }
82
+
83
+ const handleJsonRpcResult = (message) => {
84
+ Callback.resolve(message.id, message.result)
85
+ }
86
+
87
+ const handleJsonRpcMessage = async (message, handle) => {
88
+ if (message.id) {
89
+ try {
90
+ const result = requiresSocket(message.method)
91
+ ? await Command.invoke(message.method, handle, ...message.params)
92
+ : await Command.invoke(message.method, ...message.params)
93
+ electronSend({
94
+ jsonrpc: '2.0',
95
+ id: message.id,
96
+ result: result ?? null,
97
+ })
98
+ } catch (error) {
99
+ console.error('[shared process] command failed to execute')
100
+ console.error(error)
101
+ electronSend({
102
+ jsonrpc: '2.0',
103
+ code: /* ExpectedError */ -32000,
104
+ id: message.id,
105
+ error: 'ExpectedError',
106
+ // @ts-ignore
107
+ data: error.toString(),
108
+ })
74
109
  }
75
110
  } else {
76
- console.warn('unknown message', message)
111
+ // TODO handle error
112
+ Command.execute(message.method, null, ...message.params)
77
113
  }
78
114
  }
79
115
 
116
+ const handleMessageFromParentProcess = async (message, handle) => {
117
+ if (handle) {
118
+ return handleWebSocket(message, handle)
119
+ }
120
+ if (message.result) {
121
+ return handleJsonRpcResult(message)
122
+ }
123
+ if (message.method) {
124
+ return handleJsonRpcMessage(message, handle)
125
+ }
126
+ console.warn('unknown message', message)
127
+ }
128
+
80
129
  /**
81
130
  *
82
131
  * @param {{initialize:{port: MessagePort, folder:string}}} initializeMessage
@@ -160,7 +209,7 @@ const electronInitialize = (initializeMessage) => {
160
209
  },
161
210
  })
162
211
  }
163
- return
212
+
164
213
  }
165
214
  } else {
166
215
  Command.execute(message.method, fakeSocket, ...message.params)
@@ -1,21 +1,19 @@
1
- import * as Command from '../Command/Command.js'
2
1
  import * as Platform from '../Platform/Platform.js'
3
2
 
4
3
  // prettier-ignore
5
- export const __initialize__ = () => {
6
- Command.register('Platform.getConfigDir', Platform.getConfigDir)
7
- Command.register('Platform.getAppDir', Platform.getAppDir)
8
- Command.register('Platform.getHomeDir', Platform.getHomeDir)
9
- Command.register('Platform.getDataDir', Platform.getDataDir)
10
- Command.register('Platform.getExtensionsPath', Platform.getExtensionsPath)
11
- Command.register('Platform.getBuiltinExtensionsPath', Platform.getBuiltinExtensionsPath)
12
- Command.register('Platform.getDisabledExtensionsPath', Platform.getDisabledExtensionsPath)
13
- Command.register('Platform.getCachedExtensionsPath', Platform.getCachedExtensionsPath)
14
- Command.register('Platform.getMarketplaceUrl', Platform.getMarketplaceUrl)
15
- Command.register('Platform.getLogsDir', Platform.getLogsDir)
16
- Command.register('Platform.getUserSettingsPath', Platform.getUserSettingsPath)
17
- Command.register('Platform.getRecentlyOpenedPath', Platform.getRecentlyOpenedPath)
18
- Command.register('Platform.getCacheDir', Platform.getCacheDir)
19
- Command.register('Platform.getCacheDir', Platform.getCacheDir)
20
- Command.register('Platform.setEnvironmentVariables', Platform.setEnvironmentVariables)
4
+ export const Commands = {
5
+ 'Platform.getConfigDir': Platform.getConfigDir,
6
+ 'Platform.getAppDir': Platform.getAppDir,
7
+ 'Platform.getHomeDir': Platform.getHomeDir,
8
+ 'Platform.getDataDir': Platform.getDataDir,
9
+ 'Platform.getExtensionsPath': Platform.getExtensionsPath,
10
+ 'Platform.getBuiltinExtensionsPath': Platform.getBuiltinExtensionsPath,
11
+ 'Platform.getDisabledExtensionsPath': Platform.getDisabledExtensionsPath,
12
+ 'Platform.getCachedExtensionsPath': Platform.getCachedExtensionsPath,
13
+ 'Platform.getMarketplaceUrl': Platform.getMarketplaceUrl,
14
+ 'Platform.getLogsDir': Platform.getLogsDir,
15
+ 'Platform.getUserSettingsPath': Platform.getUserSettingsPath,
16
+ 'Platform.getRecentlyOpenedPath': Platform.getRecentlyOpenedPath,
17
+ 'Platform.getCacheDir': Platform.getCacheDir,
18
+ 'Platform.setEnvironmentVariables': Platform.setEnvironmentVariables,
21
19
  }
@@ -1,6 +1,6 @@
1
- import { extensionHostPath } from '@lvce-editor/extension-host'
2
1
  import { homedir, tmpdir } from 'node:os'
3
2
  import { sep } from 'node:path'
3
+ import { extensionHostPath } from '@lvce-editor/extension-host'
4
4
  import { xdgCache, xdgConfig, xdgData, xdgState } from 'xdg-basedir'
5
5
  import * as Path from '../Path/Path.js'
6
6
  import * as Root from '../Root/Root.js'
@@ -1,6 +1,5 @@
1
- import * as Command from '../Command/Command.js'
2
1
  import * as Preferences from '../Preferences/Preferences.js'
3
2
 
4
- export const __initialize__ = () => {
5
- Command.register("Preferences.getAll", Preferences.getAll)
3
+ export const Commands = {
4
+ 'Preferences.getAll': Preferences.getAll,
6
5
  }
@@ -13,8 +13,11 @@ const getActualPath = (fileUri) => {
13
13
 
14
14
  export const prepare = (error) => {
15
15
  const message = error.message
16
- if (error.cause) {
17
- error = error.cause()
16
+ if (error && error.cause) {
17
+ const cause = error.cause()
18
+ if (cause) {
19
+ error = cause
20
+ }
18
21
  }
19
22
  const cleanedStack = cleanStack(error.stack)
20
23
  const lines = cleanedStack.split('\n')
@@ -1,7 +1,6 @@
1
- import * as Command from '../Command/Command.js'
2
1
  import * as Process from './Process.js'
3
2
 
4
- export const __initialize__ = () => {
5
- Command.register(555, Process.crash)
6
- Command.register(556, Process.crashAsync)
3
+ export const Commands = {
4
+ 555: Process.crash,
5
+ 556: Process.crashAsync,
7
6
  }
@@ -1,11 +1,12 @@
1
1
  // TODO find a better way to do this
2
2
  // most commands don't require sockets
3
3
  // but output channel and terminal need to continuously send data through the socket
4
- const METHODS_THAT_REQUIRE_SOCKET = [
5
- 'OutputChannel.open', // OutputChannel.open
6
- 'ExtensionHost.start', // ExtensionHost.start
7
- ]
4
+ const METHODS_THAT_REQUIRE_SOCKET = new Set([
5
+ 'OutputChannel.open',
6
+ 'ExtensionHost.start',
7
+ 'ExtensionHost.send',
8
+ ])
8
9
 
9
10
  export const requiresSocket = (method) => {
10
- return METHODS_THAT_REQUIRE_SOCKET.includes(method)
11
+ return METHODS_THAT_REQUIRE_SOCKET.has(method)
11
12
  }
@@ -1,6 +1,5 @@
1
- import * as Command from '../Command/Command.js'
2
1
  import * as Search from './Search.js'
3
2
 
4
- export const __initialize__ = () => {
5
- Command.register('Search.search', Search.search)
3
+ export const Commands = {
4
+ 'Search.search': Search.search,
6
5
  }
@@ -1,6 +1,5 @@
1
- import * as Command from '../Command/Command.js'
2
1
  import * as SearchFile from './SearchFile.js'
3
2
 
4
- export const __initialize__ = () => {
5
- Command.register('SearchFile.searchFile', SearchFile.searchFile)
3
+ export const Commands = {
4
+ 'SearchFile.searchFile': SearchFile.searchFile,
6
5
  }
@@ -3,17 +3,17 @@
3
3
  import * as Exec from '../Exec/Exec.js'
4
4
 
5
5
  const PID_CMD =
6
- /^\s*([0-9]+)\s+([0-9]+)\s+([0-9]+\.[0-9]+)\s+([0-9]+\.[0-9]+)\s+(.+)$/
6
+ /^\s*(\d+)\s+(\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)\s+(.+)$/
7
7
 
8
8
  const parsePsOutputLine = (line) => {
9
9
  const matches = PID_CMD.exec(line.trim())
10
10
  if (matches && matches.length === 6) {
11
11
  return {
12
- pid: parseInt(matches[1]),
13
- ppid: parseInt(matches[2]),
12
+ pid: Number.parseInt(matches[1]),
13
+ ppid: Number.parseInt(matches[2]),
14
14
  cwd: matches[5],
15
- load: parseInt(matches[3]),
16
- mem: parseInt(matches[4]),
15
+ load: Number.parseInt(matches[3]),
16
+ mem: Number.parseInt(matches[4]),
17
17
  }
18
18
  }
19
19
  }
@@ -1,11 +1,11 @@
1
1
  import * as Command from '../Command/Command.js'
2
- import * as Terminal from './Terminal.js'
3
2
  import * as Assert from '../Assert/Assert.js'
3
+ import * as Terminal from './Terminal.js'
4
4
 
5
5
  const create = (socket, id, cwd) => {
6
6
  Assert.object(socket)
7
7
  if (!socket) {
8
- console.log({socket, id, cwd})
8
+ console.log({ socket, id, cwd })
9
9
  console.warn('socket not available')
10
10
  return
11
11
  }
@@ -24,8 +24,8 @@ const create = (socket, id, cwd) => {
24
24
  Terminal.create(socket, id, cwd)
25
25
  }
26
26
 
27
- const write = ( id, input) => {
28
- console.log({ id, input})
27
+ const write = (id, input) => {
28
+ console.log({ id, input })
29
29
  Terminal.write(id, input)
30
30
  }
31
31
 
@@ -37,9 +37,9 @@ const dispose = (socket, id) => {
37
37
  Terminal.dispose(id)
38
38
  }
39
39
 
40
- export const __initialize__ = () => {
41
- Command.register('Terminal.create', create)
42
- Command.register('Terminal.dispose', dispose)
43
- Command.register('Terminal.write', write)
44
- Command.register('Terminal.resize', resize)
40
+ export const Commands = {
41
+ 'Terminal.create': create,
42
+ 'Terminal.dispose': dispose,
43
+ 'Terminal.write': write,
44
+ 'Terminal.resize': resize,
45
45
  }
@@ -1,10 +1,10 @@
1
1
  import { ChildProcess, fork } from 'node:child_process'
2
2
  import exitHook from 'exit-hook'
3
+ import { ptyHostPath } from '@lvce-editor/pty-host'
3
4
  import * as Debug from '../Debug/Debug.js'
4
5
  import * as Path from '../Path/Path.js'
5
6
  import * as Root from '../Root/Root.js'
6
7
  import * as Assert from '../Assert/Assert.js'
7
- import { ptyHostPath } from '@lvce-editor/pty-host'
8
8
 
9
9
  export const state = {
10
10
  /**
@@ -1,6 +1,5 @@
1
- import * as Command from '../Command/Command.js'
2
1
  import * as TextDocument from './TextDocument.js'
3
2
 
4
- export const __initialize__ = () => {
5
- Command.register(4820, TextDocument.applyEdit)
3
+ export const Commands = {
4
+ 4820: TextDocument.applyEdit,
6
5
  }
@@ -0,0 +1,7 @@
1
+ export const setTimeout = (listener, ms) => {
2
+ return globalThis.setTimeout(listener, ms)
3
+ }
4
+
5
+ export const clearTimeout = (timeoutId) => {
6
+ globalThis.clearTimeout(timeoutId)
7
+ }
@@ -1,6 +1,5 @@
1
- import * as Command from '../Command/Command.js'
2
1
  import * as WebSocketServer from './WebSocketServer.js'
3
2
 
4
- export const __initialize__ = () => {
5
- Command.register(5621, WebSocketServer.handleUpgrade)
3
+ export const Commands = {
4
+ 5621: WebSocketServer.handleUpgrade,
6
5
  }
@@ -1,7 +1,6 @@
1
- import * as Command from '../Command/Command.js'
2
1
  import * as Workspace from './Workspace.js'
3
2
 
4
- export const __initialize__ = () => {
5
- Command.register('Workspace.resolveRoot', Workspace.resolveRoot)
6
- Command.register('Workspace.getHomeDir', Workspace.getHomeDir)
3
+ export const Commands = {
4
+ 'Workspace.resolveRoot': Workspace.resolveRoot,
5
+ 'Workspace.getHomeDir': Workspace.getHomeDir,
7
6
  }
@@ -5,9 +5,18 @@ import * as PrettyError from './parts/PrettyError/PrettyError.js'
5
5
 
6
6
  // TODO use named functions here
7
7
 
8
+ const firstErrorLine = (error) => {
9
+ if (error.stack) {
10
+ return error.stack.slice(0, error.stack.indexOf('\n'))
11
+ }
12
+ if (error.message) {
13
+ return error.message
14
+ }
15
+ return `${error}`
16
+ }
17
+
8
18
  const handleUncaughtExceptionMonitor = (error, origin) => {
9
- console.info(`[shared process] uncaught exception: ${error.stack}`)
10
- console.info('code', error.code)
19
+ console.info(`[shared process] uncaught exception: ${firstErrorLine(error)}`)
11
20
  if (error && error.code === 'EPIPE' && !process.connected) {
12
21
  // parent process is disposed, ignore
13
22
  return
@@ -16,18 +25,14 @@ const handleUncaughtExceptionMonitor = (error, origin) => {
16
25
  // parent process is disposed, ignore
17
26
  return
18
27
  }
19
- console.log(error)
28
+ // console.log(error)
20
29
  const prettyError = PrettyError.prepare(error)
21
- console.error(prettyError.message)
30
+ // console.error(prettyError.message)
22
31
  console.error(prettyError.codeFrame)
23
32
  console.error(prettyError.stack)
24
33
  process.exit(1)
25
34
  }
26
35
 
27
- const handleSigInt = () => {
28
- console.info('[shared process] sigint')
29
- }
30
-
31
36
  const handleDisconnect = () => {
32
37
  console.info('[shared process] disconnected')
33
38
  }
@@ -44,7 +49,6 @@ const main = () => {
44
49
  console.log('[shared process] started')
45
50
  process.on('beforeExit', handleBeforeExit)
46
51
  process.on('disconnect', handleDisconnect)
47
- process.on('SIGINT', handleSigInt)
48
52
  process.on('SIGTERM', handleSigTerm)
49
53
 
50
54
  process.on('uncaughtExceptionMonitor', handleUncaughtExceptionMonitor)
@@ -1,7 +0,0 @@
1
- export const install = (id) => {}
2
-
3
- export const uninstall = (id) => {}
4
-
5
- export const enable = (id) => {}
6
-
7
- export const disable = (id) => {}
@@ -1,14 +0,0 @@
1
- export const executeBraceCompletionProvider = async (
2
- extensionHost,
3
- documentId,
4
- offset,
5
- openingBrace
6
- ) => {
7
- const completions = await extensionHost.invoke(
8
- 'BraceCompletion.execute',
9
- documentId,
10
- offset,
11
- openingBrace
12
- )
13
- return completions
14
- }
@@ -1,14 +0,0 @@
1
- export const executeClosingTagProvider = async (
2
- extensionHost,
3
- documentId,
4
- offset,
5
- openingBrace
6
- ) => {
7
- const completions = await extensionHost.invoke(
8
- 'ClosingTag.execute',
9
- documentId,
10
- offset,
11
- openingBrace
12
- )
13
- return completions
14
- }
@@ -1,19 +0,0 @@
1
- import * as ExtensionManagement from '../ExtensionManagement/ExtensionManagement.js'
2
-
3
- export const executeCommand = async (extensionHost, commandId, ...args) => {
4
- return extensionHost.invoke('executeCommand', commandId, ...args)
5
- }
6
-
7
- const getExtensionCommands = (extension) => {
8
- return extension.commands || []
9
- }
10
-
11
- export const getCommands = async () => {
12
- const extensions = await ExtensionManagement.getExtensions()
13
- return extensions.flatMap(getExtensionCommands)
14
- }
15
-
16
- export const getCommandsIpc = async () => {
17
- const commands = await getCommands()
18
- return commands
19
- }
@@ -1,12 +0,0 @@
1
- export const executeCompletionProvider = async (
2
- extensionHost,
3
- documentId,
4
- offset
5
- ) => {
6
- const completions = await extensionHost.invoke(
7
- 'executeCompletionProvider',
8
- documentId,
9
- offset
10
- )
11
- return completions
12
- }
@@ -1,12 +0,0 @@
1
- export const executeDefinitionProvider = async (
2
- extensionHost,
3
- textDocumentId,
4
- offset
5
- ) => {
6
- const result = await extensionHost.invoke(
7
- 'Definition.executeDefinitionProvider',
8
- textDocumentId,
9
- offset
10
- )
11
- return result
12
- }
@@ -1,7 +0,0 @@
1
- export const executeDiagnosticProvider = async (extensionHost, documentId) => {
2
- const diagnostics = await extensionHost.invoke(
3
- 'Diagnostic.execute',
4
- documentId
5
- )
6
- return diagnostics
7
- }
@@ -1,23 +0,0 @@
1
- export const readFile = (extensionHost, protocol, uri) => {
2
- return extensionHost.invoke('FileSystem.readFile', protocol, uri)
3
- }
4
-
5
- export const writeFile = (extensionHost, protocol, uri, content) => {
6
- return extensionHost.invoke('FileSystem.writeFile', protocol, uri, content)
7
- }
8
-
9
- export const readDirWithFileTypes = (extensionHost, protocol, uri) => {
10
- return extensionHost.invoke('FileSystem.readDirWithFileTypes', protocol, uri)
11
- }
12
-
13
- export const remove = (extensionHost, protocol, uri) => {
14
- return extensionHost.invoke('FileSystem.remove', protocol, uri)
15
- }
16
-
17
- export const rename = (extensionHost, protocol, oldUri, newUri) => {
18
- return extensionHost.invoke('FileSystem.rename', protocol, oldUri, newUri)
19
- }
20
-
21
- export const getPathSeparator = (extensionHost, protocol) => {
22
- return extensionHost.invoke('FileSystem.getPathSeparator', protocol)
23
- }
@@ -1,4 +0,0 @@
1
- export const format = async (extensionHost, path, content) => {
2
- const formattedContent = await extensionHost.invoke('format', path, content)
3
- return formattedContent
4
- }