@lvce-editor/shared-process 0.0.41 → 0.2.0

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 (37) hide show
  1. package/config/defaultKeyBindings.json +5 -0
  2. package/extensions/builtin.language-basics-docker/extension.json +13 -3
  3. package/extensions/builtin.language-basics-go/extension.json +3 -2
  4. package/extensions/builtin.language-basics-json/extension.json +2 -1
  5. package/extensions/builtin.language-basics-json/src/tokenizeJson.js +6 -2
  6. package/extensions/builtin.language-basics-markdown/src/tokenizeMarkdown.js +288 -11
  7. package/extensions/builtin.language-basics-perl/README.md +14 -0
  8. package/extensions/builtin.language-basics-perl/extension.json +12 -0
  9. package/extensions/builtin.language-basics-perl/src/tokenizePerl.js +31 -0
  10. package/extensions/builtin.language-basics-plaintext/src/tokenizePlaintext.js +1 -1
  11. package/extensions/builtin.language-basics-toml/extension.json +10 -2
  12. package/extensions/builtin.theme-slime/color-theme.json +4 -0
  13. package/extensions/builtin.vscode-icons/icon-theme.json +12 -0
  14. package/extensions/builtin.vscode-icons/icons/file_type_light_objidconfig.svg +1 -1
  15. package/extensions/builtin.vscode-icons/icons/file_type_objidconfig.svg +1 -1
  16. package/extensions/builtin.vscode-icons/icons/file_type_renovate.svg +1 -1
  17. package/extensions/builtin.vscode-icons/icons/file_type_truffle.svg +1 -0
  18. package/extensions/builtin.vscode-icons/icons/file_type_unison.svg +1 -0
  19. package/package.json +6 -6
  20. package/src/parts/Command/Command.js +5 -18
  21. package/src/parts/DirentType/DirentType.js +13 -0
  22. package/src/parts/Download/Download.js +6 -8
  23. package/src/parts/ExtensionManagement/ExtensionManagement.js +16 -41
  24. package/src/parts/ExtensionManagement/ExtensionManagementColorTheme.js +4 -6
  25. package/src/parts/ExtensionManagement/ExtensionManagementIconTheme.js +4 -6
  26. package/src/parts/ExtensionManifestStatus/ExtensionManifestStatus.js +3 -0
  27. package/src/parts/FileSystem/FileSystem.js +33 -74
  28. package/src/parts/Json/Json.js +7 -55
  29. package/src/parts/JsonError/JsonError.js +70 -0
  30. package/src/parts/JsonFile/JsonFile.js +5 -5
  31. package/src/parts/Native/Native.js +2 -6
  32. package/src/parts/Preferences/Preferences.js +1 -1
  33. package/src/parts/RecentlyOpened/RecentlyOpened.ipc.js +5 -0
  34. package/src/parts/RecentlyOpened/RecentlyOpened.js +52 -0
  35. package/src/parts/Search/Search.js +9 -3
  36. package/src/parts/Electron/Electron.ipc.js +0 -18
  37. package/src/parts/Electron/Electron.js +0 -110
@@ -1,14 +1,14 @@
1
- import { mkdir, readFile, writeFile } from 'node:fs/promises'
2
- import * as Path from '../Path/Path.js'
1
+ import * as FileSystem from '../FileSystem/FileSystem.js'
3
2
  import * as Json from '../Json/Json.js'
3
+ import * as Path from '../Path/Path.js'
4
4
 
5
5
  export const readJson = async (absolutePath) => {
6
- const content = await readFile(absolutePath, 'utf-8')
6
+ const content = await FileSystem.readFile(absolutePath)
7
7
  const json = await Json.parse(content, absolutePath)
8
8
  return json
9
9
  }
10
10
 
11
11
  export const writeJson = async (absolutePath, value) => {
12
- await mkdir(Path.dirname(absolutePath), { recursive: true })
13
- await writeFile(absolutePath, Json.stringify(value))
12
+ await FileSystem.mkdir(Path.dirname(absolutePath))
13
+ await FileSystem.writeFile(absolutePath, Json.stringify(value))
14
14
  }
@@ -1,14 +1,10 @@
1
1
  import open from 'open'
2
- import * as Error from '../Error/Error.js'
2
+ import VError from 'verror'
3
3
 
4
4
  export const openFolder = async (path) => {
5
5
  try {
6
6
  await open(path)
7
7
  } catch (error) {
8
- throw new Error.OperationalError({
9
- cause: error,
10
- code: 'E_OPEN_SYSTEM_ERROR',
11
- message: `Failed to open ${path}`,
12
- })
8
+ throw new VError(error, `Failed to open ${path}`)
13
9
  }
14
10
  }
@@ -11,7 +11,7 @@ export const getUserPreferences = async () => {
11
11
  try {
12
12
  json = await JsonFile.readJson(userSettingsPath)
13
13
  } catch (error) {
14
- if (error && error.code === 'ENOENT') {
14
+ if (error && error.message.includes('File not found')) {
15
15
  return {}
16
16
  }
17
17
  throw error
@@ -0,0 +1,5 @@
1
+ import * as RecentlyOpened from './RecentlyOpened.js'
2
+
3
+ export const Commands = {
4
+ 'RecentlyOpened.addPath': RecentlyOpened.addPath,
5
+ }
@@ -0,0 +1,52 @@
1
+ import VError from 'verror'
2
+ import * as Assert from '../Assert/Assert.js'
3
+ import * as FileSystem from '../FileSystem/FileSystem.js'
4
+ import * as Json from '../Json/Json.js'
5
+ import * as Platform from '../Platform/Platform.js'
6
+
7
+ const isValid = (recentlyOpened) => {
8
+ return recentlyOpened && Array.isArray(recentlyOpened)
9
+ }
10
+
11
+ const addToArrayUnique = (recentlyOpened, path) => {
12
+ const index = recentlyOpened.indexOf(path)
13
+ if (index === -1) {
14
+ return [path, ...recentlyOpened]
15
+ }
16
+ return [
17
+ path,
18
+ ...recentlyOpened.slice(0, index),
19
+ ...recentlyOpened.slice(index + 1),
20
+ ]
21
+ }
22
+
23
+ const getRecentlyOpened = async (recentlyOpenedPath) => {
24
+ try {
25
+ const content = await FileSystem.readFile(recentlyOpenedPath)
26
+ const parsed = await Json.parse(content, recentlyOpenedPath)
27
+ return parsed
28
+ } catch (error) {
29
+ // TODO should check for error.code
30
+ if (error.message.includes('File not found')) {
31
+ // ignore
32
+ } else if (error.message.includes('Json Parsing Error')) {
33
+ // ignore
34
+ } else {
35
+ throw new VError(error, `Failed to read recently opened`)
36
+ }
37
+ return []
38
+ }
39
+ }
40
+
41
+ const setRecentlyOpened = async (recentlyOpenedPath, newRecentlyOpened) => {
42
+ const stringified = Json.stringify(newRecentlyOpened)
43
+ await FileSystem.writeFile(recentlyOpenedPath, stringified)
44
+ }
45
+
46
+ export const addPath = async (path) => {
47
+ Assert.string(path)
48
+ const recentlyOpenedPath = Platform.getRecentlyOpenedPath()
49
+ const parsed = await getRecentlyOpened(recentlyOpenedPath)
50
+ const newRecentlyOpened = addToArrayUnique(parsed, path)
51
+ await setRecentlyOpened(recentlyOpenedPath, newRecentlyOpened)
52
+ }
@@ -22,6 +22,12 @@ const useNice = !Platform.isWindows()
22
22
  // TODO update client
23
23
  // TODO not always run nice, maybe configure nice via flag/options
24
24
 
25
+ const ParsedLineType = {
26
+ Begin: 'begin',
27
+ Match: 'match',
28
+ Summary: 'summary',
29
+ }
30
+
25
31
  export const search = async (searchDir, searchString) => {
26
32
  // TODO reject promise when ripgrep search fails
27
33
  return new Promise((resolve, reject) => {
@@ -61,18 +67,18 @@ export const search = async (searchDir, searchString) => {
61
67
  for (const line of lines) {
62
68
  const parsedLine = JSON.parse(line)
63
69
  switch (parsedLine.type) {
64
- case 'begin': {
70
+ case ParsedLineType.Begin: {
65
71
  allSearchResults[parsedLine.data.path.text] = []
66
72
  break
67
73
  }
68
- case 'match': {
74
+ case ParsedLineType.Match: {
69
75
  numberOfResults++
70
76
  allSearchResults[parsedLine.data.path.text].push(
71
77
  toSearchResult(parsedLine)
72
78
  )
73
79
  break
74
80
  }
75
- case 'summary':
81
+ case ParsedLineType.Summary:
76
82
  stats = parsedLine.data
77
83
  break
78
84
  default:
@@ -1,18 +0,0 @@
1
- import * as Electron from './Electron.js'
2
-
3
- export const Commands = {
4
- 'Electron.toggleDevtools': Electron.toggleDevtools,
5
- 'Electron.windowMinimize': Electron.windowMinimize,
6
- 'Electron.windowMaximize': Electron.windowMaximize,
7
- 'Electron.windowUnmaximize': Electron.windowUnmaximize,
8
- 'Electron.windowClose': Electron.windowClose,
9
- 'Electron.about': Electron.about,
10
- 'Electron.showOpenDialog': Electron.showOpenDialog,
11
- 'Electron.windowReload': Electron.windowReload,
12
- 'Electron.getPerformanceEntries': Electron.getPerformanceEntries,
13
- 'Electron.crashMainProcess': Electron.crashMainProcess,
14
- 'Electron.showMessageBox': Electron.showMessageBox,
15
- 'Electron.windowOpenNew': Electron.windowOpenNew,
16
- 'Electron.exit': Electron.exit,
17
- 'Electron.openProcessExplorer': Electron.openProcessExplorer,
18
- }
@@ -1,110 +0,0 @@
1
- import * as Callback from '../Callback/Callback.js'
2
- import * as ParentIpc from '../ParentIpc/ParentIpc.js'
3
-
4
- export const state = {
5
- send(message) {
6
- ParentIpc.electronSend(message)
7
- },
8
- async invoke(method, ...params) {
9
- return new Promise((resolve, reject) => {
10
- // TODO use one map instead of two
11
- const callbackId = Callback.register(resolve, reject)
12
- state.send({
13
- jsonrpc: '2.0',
14
- method,
15
- params,
16
- id: callbackId,
17
- })
18
- })
19
- },
20
- }
21
-
22
- const send = (method, ...params) => {
23
- state.send({
24
- jsonrpc: '2.0',
25
- method,
26
- params,
27
- })
28
- }
29
-
30
- const invoke = async (method, ...params) => {
31
- return state.invoke(method, ...params)
32
- }
33
-
34
- export const toggleDevtools = async () => {
35
- await invoke(/* Window.toggleDevtools */ 'Window.toggleDevtools')
36
- }
37
-
38
- export const windowMinimize = async () => {
39
- await invoke(/* Window.minimize */ 'Window.minimize')
40
- }
41
-
42
- export const windowMaximize = async () => {
43
- await invoke(/* Window.maximize */ 'Window.maximize')
44
- }
45
-
46
- export const windowUnmaximize = async () => {
47
- await invoke(/* Window.unmaximize */ 'Window.unmaximize')
48
- }
49
-
50
- export const windowClose = async () => {
51
- await invoke(/* Window.close */ 'Window.close')
52
- }
53
-
54
- export const windowReload = async () => {
55
- await invoke(/* Window.reload */ 'Window.reload')
56
- }
57
-
58
- // TODO move these into separate files like done extension host
59
-
60
- export const windowOpenNew = async () => {
61
- await invoke(/* AppWindow.openNew */ 'AppWindow.openNew')
62
- }
63
-
64
- export const about = async () => {
65
- await invoke(/* About.open */ 'About.open')
66
- }
67
-
68
- export const showOpenDialog = async (title, properties) => {
69
- const result = await invoke(
70
- /* Dialog.showOpenDialog */ 'Dialog.showOpenDialog',
71
- /* title */ title,
72
- /* properties */ properties
73
- )
74
- return result
75
- }
76
-
77
- export const showMessageBox = async (message, buttons) => {
78
- const result = await invoke(
79
- /* Dialog.showMessageBox */ 'Dialog.showMessageBox',
80
- message,
81
- buttons
82
- )
83
- return result
84
- }
85
-
86
- export const crashMainProcess = async () => {
87
- await invoke(/* Developer.crashMainProcess */ 'Developer.crashMainProcess')
88
- }
89
-
90
- export const getPerformanceEntries = async () => {
91
- const result = await invoke(
92
- /* Developer.getPerformanceEntries */ 'Developer.getPerformanceEntries'
93
- )
94
- return result
95
- }
96
-
97
- export const beep = async () => {
98
- // TODO when is remote should send to renderer worker
99
- await invoke(/* Beep.beep */ 'Beep.beep')
100
- }
101
-
102
- export const exit = async () => {
103
- await invoke(/* App.exit */ 'App.exit')
104
- }
105
-
106
- export const openProcessExplorer = async () => {
107
- await invoke(
108
- /* ProcessExplorer.openProcessExplorer */ 'ProcessExplorer.openProcessExplorer'
109
- )
110
- }