@lvce-editor/shared-process 0.11.7 → 0.11.9
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.
- package/config/defaultKeyBindings.json +4 -0
- package/config/defaultSettings.json +2 -0
- package/extensions/builtin.language-basics-cpp/src/tokenizeCpp.js +29 -6
- package/extensions/builtin.language-basics-css/src/tokenizeCss.js +176 -25
- package/extensions/builtin.language-basics-gn/README.md +14 -0
- package/extensions/builtin.language-basics-gn/extension.json +12 -0
- package/extensions/builtin.language-basics-gn/src/tokenizeGn.js +178 -0
- package/extensions/builtin.language-basics-javascript/src/tokenizeJavaScript.js +5 -0
- package/extensions/builtin.language-basics-json5/README.md +16 -0
- package/extensions/builtin.language-basics-json5/extension.json +12 -0
- package/extensions/builtin.language-basics-json5/src/tokenizeJson5.js +321 -0
- package/extensions/builtin.language-basics-perl/extension.json +2 -1
- package/extensions/builtin.language-basics-perl/src/tokenizePerl.js +53 -6
- package/extensions/builtin.language-basics-python/extension.json +2 -1
- package/extensions/builtin.language-basics-python/src/tokenizePython.js +129 -36
- package/extensions/builtin.language-basics-shellscript/src/tokenizeShellScript.js +274 -13
- package/extensions/builtin.language-basics-typescript/src/tokenizeTypeScript.js +197 -15
- package/extensions/builtin.theme-ayu/color-theme.json +2 -0
- package/extensions/builtin.theme-slime/color-theme.json +6 -0
- package/package.json +4 -4
- package/src/parts/Command/Command.js +38 -40
- package/src/parts/ErrorCodes/ErrorCodes.js +9 -17
- package/src/parts/GetResponse/GetResponse.js +2 -2
- package/src/parts/Module/Module.js +2 -2
- package/src/parts/ModuleMap/ModuleMap.js +1 -1
- package/src/parts/PrettyError/PrettyError.js +55 -5
- package/src/parts/RipGrep/RipGrep.js +30 -0
- package/src/parts/SearchFile/SearchFile.js +12 -16
- package/src/parts/TextSearch/TextSearch.ipc.js +7 -0
- package/src/parts/{Search/Search.js → TextSearch/TextSearch.js} +11 -17
- package/src/parts/Search/Search.ipc.js +0 -7
|
@@ -3,6 +3,8 @@ import cleanStack from 'clean-stack'
|
|
|
3
3
|
import { LinesAndColumns } from 'lines-and-columns'
|
|
4
4
|
import { readFileSync } from 'node:fs'
|
|
5
5
|
import { fileURLToPath } from 'node:url'
|
|
6
|
+
import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
|
|
7
|
+
import * as Json from '../Json/Json.js'
|
|
6
8
|
import * as SplitLines from '../SplitLines/SplitLines.js'
|
|
7
9
|
|
|
8
10
|
const getActualPath = (fileUri) => {
|
|
@@ -12,7 +14,59 @@ const getActualPath = (fileUri) => {
|
|
|
12
14
|
return fileUri
|
|
13
15
|
}
|
|
14
16
|
|
|
17
|
+
const RE_MODULE_NOT_FOUND_STACK =
|
|
18
|
+
/Cannot find package '([^']+)' imported from (.+)$/
|
|
19
|
+
|
|
20
|
+
const prepareModuleNotFoundError = (error) => {
|
|
21
|
+
const message = error.message
|
|
22
|
+
const match = message.match(RE_MODULE_NOT_FOUND_STACK)
|
|
23
|
+
if (!match) {
|
|
24
|
+
return {
|
|
25
|
+
message,
|
|
26
|
+
stack: error.stack,
|
|
27
|
+
codeFrame: '',
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const notFoundModule = match[1]
|
|
31
|
+
const importedFrom = match[2]
|
|
32
|
+
const rawLines = readFileSync(importedFrom, 'utf-8')
|
|
33
|
+
let line = 0
|
|
34
|
+
let column = 0
|
|
35
|
+
const splittedLines = rawLines.split('\n')
|
|
36
|
+
for (let i = 0; i < splittedLines.length; i++) {
|
|
37
|
+
const splittedLine = splittedLines[i]
|
|
38
|
+
const index = splittedLine.indexOf(notFoundModule)
|
|
39
|
+
if (index !== -1) {
|
|
40
|
+
line = i + 1
|
|
41
|
+
column = index
|
|
42
|
+
break
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const location = {
|
|
46
|
+
start: {
|
|
47
|
+
line,
|
|
48
|
+
column,
|
|
49
|
+
},
|
|
50
|
+
}
|
|
51
|
+
const codeFrame = codeFrameColumns(rawLines, location)
|
|
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')
|
|
59
|
+
return {
|
|
60
|
+
message,
|
|
61
|
+
stack: newStack,
|
|
62
|
+
codeFrame,
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
15
66
|
export const prepare = (error) => {
|
|
67
|
+
if (error && error.code === ErrorCodes.ERR_MODULE_NOT_FOUND) {
|
|
68
|
+
return prepareModuleNotFoundError(error)
|
|
69
|
+
}
|
|
16
70
|
const message = error.message
|
|
17
71
|
if (error && error.cause) {
|
|
18
72
|
const cause = error.cause()
|
|
@@ -57,12 +111,8 @@ const fixBackslashes = (string) => {
|
|
|
57
111
|
return string.replaceAll('\\\\', '\\')
|
|
58
112
|
}
|
|
59
113
|
|
|
60
|
-
const stringifyJson = (json) => {
|
|
61
|
-
return JSON.stringify(json, null, 2) + '\n'
|
|
62
|
-
}
|
|
63
|
-
|
|
64
114
|
export const prepareJsonError = (json, property, message) => {
|
|
65
|
-
const string = fixBackslashes(
|
|
115
|
+
const string = fixBackslashes(Json.stringify(json))
|
|
66
116
|
const stringifiedPropertyName = `"${property}"`
|
|
67
117
|
const index = string.indexOf(stringifiedPropertyName) // TODO this could be wrong in some cases, find a better way
|
|
68
118
|
console.log({ string, index })
|
|
@@ -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
|
|
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
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
47
|
-
|
|
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
|
-
|
|
54
|
-
return
|
|
49
|
+
Logger.error(error)
|
|
50
|
+
return ``
|
|
55
51
|
}
|
|
56
52
|
}
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import
|
|
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
|
|
10
|
-
const
|
|
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 -
|
|
18
|
-
const previewEnd = Math.min(submatch.end +
|
|
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 =
|
|
56
|
-
|
|
57
|
-
|
|
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 = {}
|