parent
58f461b621
commit
605946b19d
@ -0,0 +1,12 @@ |
||||
import { ElectronPlugin } from '@remixproject/engine-electron'; |
||||
|
||||
export class ripgrepPlugin extends ElectronPlugin { |
||||
constructor(){ |
||||
super({ |
||||
displayName: 'ripgrep', |
||||
name: 'ripgrep', |
||||
description: 'ripgrep' |
||||
}) |
||||
this.methods = ['glob'] |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,97 @@ |
||||
import { PluginClient } from "@remixproject/plugin"; |
||||
import { Profile } from "@remixproject/plugin-utils"; |
||||
import { ElectronBasePlugin, ElectronBasePluginClient } from "@remixproject/plugin-electron" |
||||
import path from "path"; |
||||
import { rgPath } from "@vscode/ripgrep"; |
||||
import byline from "byline"; |
||||
import { spawn } from "child_process"; |
||||
|
||||
const profile: Profile = { |
||||
name: 'ripgrep', |
||||
displayName: 'ripgrep', |
||||
description: 'Ripgrep plugin', |
||||
} |
||||
|
||||
const convertPathToPosix = (pathName: string): string => { |
||||
return pathName.split(path.sep).join(path.posix.sep) |
||||
} |
||||
|
||||
|
||||
export class RipgrepPlugin extends ElectronBasePlugin { |
||||
clients: RipgrepPluginClient[] = [] |
||||
constructor() { |
||||
console.log('constructor ripgrepPlugin') |
||||
super(profile, clientProfile, RipgrepPluginClient) |
||||
this.methods = [...super.methods] |
||||
} |
||||
} |
||||
|
||||
const clientProfile: Profile = { |
||||
name: 'ripgrep', |
||||
displayName: 'ripgrep', |
||||
description: 'ripgrep plugin', |
||||
methods: ['glob'] |
||||
} |
||||
|
||||
export class RipgrepPluginClient extends ElectronBasePluginClient { |
||||
workingDir: string = '' |
||||
constructor(webContentsId: number, profile: Profile) { |
||||
super(webContentsId, profile) |
||||
console.log('constructor ripgrepPluginClient') |
||||
|
||||
this.onload(() => { |
||||
console.log('onload ripgrepPluginClient') |
||||
this.on('fs' as any, 'workingDirChanged', async (path: string) => { |
||||
this.workingDir = path |
||||
}) |
||||
}) |
||||
|
||||
} |
||||
|
||||
async glob(path: string, pattern: string, options?: any) { |
||||
path = convertPathToPosix(this.fixPath(path)) |
||||
|
||||
return new Promise((c, e) => { |
||||
console.log('PATH rg', path) |
||||
|
||||
const rg = spawn(rgPath, ['.', '-l', path]) |
||||
|
||||
const resultrg: any[] = [] |
||||
|
||||
const stream = byline(rg.stdout.setEncoding('utf8')) |
||||
stream.on('data', (rgresult: string) => { |
||||
console.log(this.workingDir) |
||||
let pathWithoutWorkingDir = rgresult.replace(this.workingDir, '') |
||||
if (pathWithoutWorkingDir.endsWith('/')) { |
||||
pathWithoutWorkingDir = pathWithoutWorkingDir.slice(0, -1) |
||||
} |
||||
if (pathWithoutWorkingDir.startsWith('/')) { |
||||
pathWithoutWorkingDir = pathWithoutWorkingDir.slice(1) |
||||
} |
||||
if (pathWithoutWorkingDir.startsWith('\\')) { |
||||
pathWithoutWorkingDir = pathWithoutWorkingDir.slice(1) |
||||
} |
||||
resultrg.push({ |
||||
path: pathWithoutWorkingDir, |
||||
isDirectory: false, |
||||
}) |
||||
}) |
||||
stream.on('end', () => { |
||||
console.log('rg', resultrg) |
||||
c(resultrg) |
||||
}) |
||||
}) |
||||
|
||||
} |
||||
|
||||
fixPath(path: string): string { |
||||
if (this.workingDir === '') throw new Error('workingDir is not set') |
||||
if (path) { |
||||
if (path.startsWith('/')) { |
||||
path = path.slice(1) |
||||
} |
||||
} |
||||
path = this.workingDir + (!this.workingDir.endsWith('/') ? '/' : '') + path |
||||
return path |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue