@lvce-editor/shared-process 0.11.7 → 0.11.8

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 (28) hide show
  1. package/config/defaultKeyBindings.json +4 -0
  2. package/config/defaultSettings.json +2 -0
  3. package/extensions/builtin.language-basics-cpp/src/tokenizeCpp.js +29 -6
  4. package/extensions/builtin.language-basics-css/src/tokenizeCss.js +176 -25
  5. package/extensions/builtin.language-basics-gn/README.md +14 -0
  6. package/extensions/builtin.language-basics-gn/extension.json +12 -0
  7. package/extensions/builtin.language-basics-gn/src/tokenizeGn.js +178 -0
  8. package/extensions/builtin.language-basics-javascript/src/tokenizeJavaScript.js +5 -0
  9. package/extensions/builtin.language-basics-json5/README.md +16 -0
  10. package/extensions/builtin.language-basics-json5/extension.json +12 -0
  11. package/extensions/builtin.language-basics-json5/src/tokenizeJson5.js +321 -0
  12. package/extensions/builtin.language-basics-python/extension.json +2 -1
  13. package/extensions/builtin.language-basics-python/src/tokenizePython.js +45 -35
  14. package/extensions/builtin.language-basics-typescript/src/tokenizeTypeScript.js +197 -15
  15. package/extensions/builtin.theme-ayu/color-theme.json +2 -0
  16. package/extensions/builtin.theme-slime/color-theme.json +6 -0
  17. package/package.json +4 -4
  18. package/src/parts/Command/Command.js +38 -40
  19. package/src/parts/ErrorCodes/ErrorCodes.js +2 -0
  20. package/src/parts/GetResponse/GetResponse.js +2 -2
  21. package/src/parts/Module/Module.js +2 -2
  22. package/src/parts/ModuleMap/ModuleMap.js +1 -1
  23. package/src/parts/PrettyError/PrettyError.js +55 -5
  24. package/src/parts/RipGrep/RipGrep.js +30 -0
  25. package/src/parts/SearchFile/SearchFile.js +12 -16
  26. package/src/parts/TextSearch/TextSearch.ipc.js +7 -0
  27. package/src/parts/{Search/Search.js → TextSearch/TextSearch.js} +11 -17
  28. package/src/parts/Search/Search.ipc.js +0 -7
@@ -0,0 +1,30 @@
1
+ import * as NodeChildProcess from 'node:child_process'
2
+ import * as Assert from '../Assert/Assert.js'
3
+ import * as Exec from '../Exec/Exec.js'
4
+ import * as RgPath from '../RgPath/RgPath.js'
5
+
6
+ export const ripGrepPath = process.env.RIP_GREP_PATH || RgPath.rgPath
7
+
8
+ export const spawn = (args, options) => {
9
+ const childProcess = NodeChildProcess.spawn(RgPath.rgPath, args, options)
10
+ return {
11
+ on(event, listener) {
12
+ childProcess.on(event, listener)
13
+ },
14
+ once(event, listener) {
15
+ childProcess.once(event, listener)
16
+ },
17
+ stdout: childProcess.stdout,
18
+ stderr: childProcess.stderr,
19
+ kill() {
20
+ childProcess.kill()
21
+ },
22
+ }
23
+ }
24
+
25
+ export const exec = async (args, options) => {
26
+ Assert.array(args)
27
+ Assert.object(options)
28
+ const { stdout, stderr } = await Exec.exec(ripGrepPath, args, options)
29
+ return { stdout, stderr }
30
+ }
@@ -1,10 +1,8 @@
1
1
  import * as Assert from '../Assert/Assert.js'
2
2
  import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
3
- import * as Exec from '../Exec/Exec.js'
4
3
  import * as LimitString from '../LimitString/LimitString.js'
5
- import * as RgPath from '../RgPath/RgPath.js'
6
-
7
- const ripGrepPath = process.env.RIP_GREP_PATH || RgPath.rgPath
4
+ import * as RipGrep from '../RipGrep/RipGrep.js'
5
+ import * as Logger from '../Logger/Logger.js'
8
6
 
9
7
  const isEnoentErrorLinux = (error) => {
10
8
  return error.code === ErrorCodes.ENOENT
@@ -32,25 +30,23 @@ export const searchFile = async (path, searchTerm, limit) => {
32
30
  Assert.string(path)
33
31
  Assert.string(searchTerm)
34
32
  Assert.number(limit)
35
- const { stdout, stderr } = await Exec.exec(
36
- ripGrepPath,
37
- ['--files', '--sort-files'],
38
- {
39
- cwd: path,
40
- }
41
- )
33
+ const { stdout, stderr } = await RipGrep.exec(['--files', '--sort-files'], {
34
+ cwd: path,
35
+ })
42
36
  return LimitString.limitString(stdout, limit)
43
37
  } catch (error) {
44
38
  // @ts-ignore
45
39
  if (isEnoentError(error)) {
46
- console.info(`[info] ripgrep could not be found at "${ripGrepPath}"`)
47
- return []
40
+ Logger.info(
41
+ `[shared-process] ripgrep could not be found at "${RipGrep.ripGrepPath}"`
42
+ )
43
+ return ``
48
44
  }
49
45
  // @ts-ignore
50
46
  if (error && error.stderr === '') {
51
- return []
47
+ return ``
52
48
  }
53
- console.error(error)
54
- return []
49
+ Logger.error(error)
50
+ return ``
55
51
  }
56
52
  }
@@ -0,0 +1,7 @@
1
+ import * as TextSearch from './TextSearch.js'
2
+
3
+ export const name = 'TextSearch'
4
+
5
+ export const Commands = {
6
+ search: TextSearch.search,
7
+ }
@@ -1,21 +1,19 @@
1
- import { spawn } from 'node:child_process'
2
- import * as Platform from '../Platform/Platform.js'
3
- import * as RgPath from '../RgPath/RgPath.js'
1
+ import * as RipGrep from '../RipGrep/RipGrep.js'
4
2
  import * as RipGrepParsedLineType from '../RipGrepParsedLineType/RipGrepParsedLineType.js'
5
3
  import * as TextSearchResultType from '../TextSearchResultType/TextSearchResultType.js'
6
4
 
7
5
  const MAX_SEARCH_RESULTS = 300
8
6
 
9
- const BEFORE = 20
10
- const AFTER = 20
7
+ const CHARS_BEFORE = 20
8
+ const CHARS_AFTER = 50
11
9
 
12
10
  const toSearchResult = (parsedLine) => {
13
11
  const results = []
14
12
  const lines = parsedLine.data.lines.text
15
13
  const lineNumber = parsedLine.data.line_number
16
14
  for (const submatch of parsedLine.data.submatches) {
17
- const previewStart = Math.max(submatch.start - BEFORE, 0)
18
- const previewEnd = Math.min(submatch.end + AFTER, lines.length)
15
+ const previewStart = Math.max(submatch.start - CHARS_BEFORE, 0)
16
+ const previewEnd = Math.min(submatch.end + CHARS_AFTER, lines.length)
19
17
  const previewText = lines.slice(previewStart, previewEnd)
20
18
  results.push({
21
19
  type: TextSearchResultType.Match,
@@ -35,30 +33,26 @@ const toSearchResult = (parsedLine) => {
35
33
  // issue 2 https://github.com/BurntSushi/ripgrep/issues/1892
36
34
  // remove workaround when ripgrep is fixed
37
35
 
38
- // TODO no function call at toplevel!
39
- const useNice = !Platform.isWindows
40
36
  // TODO stats flag might not be necessary
41
37
  // TODO update client
42
38
  // TODO not always run nice, maybe configure nice via flag/options
43
39
 
44
- export const search = async (searchDir, searchString) => {
40
+ export const search = async (searchDir, searchString, { threads = 1 } = {}) => {
45
41
  // TODO reject promise when ripgrep search fails
46
42
  return new Promise((resolve, reject) => {
47
43
  const ripGrepArgs = [
48
44
  '--smart-case',
49
45
  '--stats',
50
46
  '--json',
47
+ '--threads',
48
+ `${threads}`,
51
49
  '--fixed-strings',
52
50
  searchString,
53
51
  '.',
54
52
  ]
55
- const childProcess = useNice
56
- ? spawn('nice', ['-20', RgPath.rgPath, ...ripGrepArgs], {
57
- cwd: searchDir,
58
- })
59
- : spawn(RgPath.rgPath, ripGrepArgs, {
60
- cwd: searchDir,
61
- })
53
+ const childProcess = RipGrep.spawn(ripGrepArgs, {
54
+ cwd: searchDir,
55
+ })
62
56
  const allSearchResults = Object.create(null)
63
57
  let buffer = ''
64
58
  let stats = {}
@@ -1,7 +0,0 @@
1
- import * as Search from './Search.js'
2
-
3
- export const name = 'Search'
4
-
5
- export const Commands = {
6
- search: Search.search,
7
- }