ripgrep tests

rdesktop2
filip mertens 1 year ago
parent ee56ee6a0e
commit cb32ecbd31
  1. 2
      apps/remixdesktop/README.txt
  2. 109
      apps/remixdesktop/src/main.ts
  3. 2
      apps/remixdesktop/src/plugins/fsPlugin.ts
  4. 2
      apps/remixdesktop/src/tools/search.ts
  5. 1
      libs/remix-ui/search/src/lib/components/results/ResultItem.tsx
  6. 4
      libs/remix-ui/search/src/lib/context/context.tsx

@ -0,0 +1,2 @@
bunsenstraat test bunsenstraat
bunsenstraat testing

@ -26,7 +26,7 @@ export const createWindow = async (dir?: string): Promise<void> => {
preload: path.join(__dirname, 'preload.js')
},
});
if(dir && dir.endsWith('/')) dir = dir.slice(0, -1)
if (dir && dir.endsWith('/')) dir = dir.slice(0, -1)
let params = dir ? `?opendir=${encodeURIComponent(dir)}` : '';
// and load the index.html of the app.
mainWindow.loadURL(
@ -35,7 +35,7 @@ export const createWindow = async (dir?: string): Promise<void> => {
mainWindow.maximize();
if(dir){
if (dir) {
mainWindow.setTitle(dir)
}
@ -128,11 +128,106 @@ searchProxy.checkIfSelectStringIsInstalled().then((result) => {
})
*/
searchProxy.checkIfRgIsInstalled().then((result) => {
console.log('rg --version', result)
interface position {
start: {
line: number
column: number
},
end: {
line: number
column: number
}
}
).catch((error) => {
console.log('rg --version', error)
})
export interface SearchResultLineLine {
left: any,
center: any,
right: any,
position: position
}
export interface SearchResultLine {
lines: SearchResultLineLine[]
}
import * as cp from 'child_process';
import { rgPath } from '@vscode/ripgrep';
const rgDiskPath = rgPath.replace(/\bnode_modules\.asar\b/, 'node_modules.asar.unpacked');
console.log('rgDiskPath', rgDiskPath)
// ripgrep
// -s means case sensitive
// -i means ignore case
// -F means fixed strings so not regex
/*
-g, --glob GLOB ...
Include or exclude files and directories for searching that match the given glob. This always overrides any other ignore logic. Multiple glob flags may be used. Globbing rules match .gitignore globs. Precede a glob with a ! to exclude it. If multiple globs match a file or directory, the glob given later in the command line takes precedence.
*/
console.log('process.cwd()', process.cwd())
const child = cp.spawn(rgDiskPath, ['bunsens[a-z]*', '--json', './'], { cwd: process.cwd() });
child.on('error', (err) => {
console.log('error', err)
}
)
child.stdout.on('data', (data) => {
const lines: string[] = data.toString().split('\n')
lines.forEach(line => {
if (line) {
try {
const result = JSON.parse(line)
if (result && result.type && result.type === 'match') {
//console.log('line:', result)
//console.log('path:', result.data.path.text)
//console.log('line:', result.data.lines.text)
//console.log('submatch: ', result.data.submatches)
let searchResultLine: SearchResultLine = {
lines: []
}
result.data.submatches.forEach((submatch: any) => {
searchResultLine.lines.push({
left: result.data.lines.text.substring(0, submatch.start),
center: result.data.lines.text.substring(submatch.start, submatch.end),
right: result.data.lines.text.substring(submatch.end),
position: {
start: {
line: result.data.line_number,
column: submatch.start,
},
end: {
line: result.data.line_number,
column: submatch.end,
},
},
})
})
console.log('searchResultLine', searchResultLine)
}
} catch (e) {
console.log('error ripgrep', e)
}
}
})
//console.log('stdout', lines)
}
)
child.stderr.on('data', (data) => {
console.log('stderr', data.toString())
}
)
child.on('close', (code) => {
console.log('close', code)
}
)
child.on('exit', (code) => {
console.log('exit', code)
}
)

@ -55,7 +55,7 @@ export class FSPlugin extends ElectronBasePlugin {
}
}else{
console.log('no opened folders')
createWindow()
//createWindow()
}
}

@ -42,7 +42,7 @@ export const searchProxy = {
checkIfRgIsInstalled: async () => {
try {
const result = await execAsync(`${rgDiskPath} 'remix'`, { cwd: process.cwd(), env: { PATH: process.env.PATH }});
const result = await execAsync(`${rgDiskPath} 'remix' ./`, { cwd: process.cwd(), env: { PATH: process.env.PATH }});
console.log('rg --version', result.stdout)
return result.stdout
} catch (error) {

@ -79,6 +79,7 @@ export const ResultItem = (props: ResultItemProps) => {
const doLoad = () => {
if(!subscribed.current) return
console.log('DO LOAD')
findText(props.file.filename).then(res => {
if (subscribed.current) {
setLines(res)

@ -193,6 +193,7 @@ export const SearchProvider = ({
},
findText: async (path: string) => {
if (!plugin) return
try {
if (state.find.length < 1) return
@ -202,6 +203,7 @@ export const SearchProvider = ({
text,
createRegExFromFind()
)
console.log('RESULT', result)
clearTimeout(clearSearchingTimeout.current)
clearSearchingTimeout.current = setTimeout(() => value.setSearching(null), 500)
return result
@ -421,7 +423,7 @@ export const SearchProvider = ({
}, [state.count])
useEffect(() => {
console.log('STATE CHANGED', files)
console.log('STATE CHANGED', files, state.find)
if (state.find) {
(async () => {
try {

Loading…
Cancel
Save