desktopmerge
filip mertens 1 year ago
parent 58f461b621
commit 605946b19d
  1. 6
      apps/remix-ide/src/app.js
  2. 12
      apps/remix-ide/src/app/plugins/electron/ripgrepPlugin.ts
  3. 2
      apps/remix-ide/src/app/plugins/parser/services/code-parser-imports.ts
  4. 8746
      apps/remixdesktop/package-lock.json
  5. 4
      apps/remixdesktop/package.json
  6. 4
      apps/remixdesktop/src/engine.ts
  7. 85
      apps/remixdesktop/src/plugins/fsPlugin.ts
  8. 97
      apps/remixdesktop/src/plugins/ripgrepPlugin.ts
  9. 2
      apps/remixdesktop/src/preload.ts
  10. 1369
      apps/remixdesktop/yarn.lock
  11. 2
      libs/remix-ui/search/src/lib/components/results/SearchHelper.ts

@ -53,6 +53,7 @@ import { isoGitPlugin } from './app/plugins/electron/isoGitPlugin'
import { electronConfig } from './app/plugins/electron/electronConfigPlugin'
import { electronTemplates } from './app/plugins/electron/templatesPlugin'
import { xtermPlugin } from './app/plugins/electron/xtermPlugin'
import { ripgrepPlugin } from './app/plugins/electron/ripgrepPlugin'
import {OpenAIGpt} from './app/plugins/openaigpt'
const isElectron = require('is-electron')
@ -341,6 +342,8 @@ class AppComponent {
this.engine.register([templatesPlugin])
const xterm = new xtermPlugin()
this.engine.register([xterm])
const ripgrep = new ripgrepPlugin()
this.engine.register([ripgrep])
}
// LAYOUT & SYSTEM VIEWS
@ -452,11 +455,12 @@ class AppComponent {
'gistHandler'
])
await this.appManager.activatePlugin(['settings'])
await this.appManager.activatePlugin(['walkthrough', 'storage', 'search', 'compileAndRun', 'recorder'])
await this.appManager.activatePlugin(['solidity-script', 'remix-templates'])
if(isElectron()){
await this.appManager.activatePlugin(['fs', 'isogit', 'electronconfig', 'electronTemplates', 'xterm'])
await this.appManager.activatePlugin(['fs', 'isogit', 'electronconfig', 'electronTemplates', 'xterm', 'ripgrep'])
}
this.appManager.on(

@ -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']
}
}

@ -41,7 +41,7 @@ export default class CodeParserImports {
setFileTree = async () => {
if (isElectron()) {
const files = await this.plugin.call('fs', 'glob', '/', '**/*.sol')
const files = await this.plugin.call('ripgrep', 'glob', '/', '**/*.sol')
// only get path property of files
this.data.files = files.map((x) => x.path)
} else {

File diff suppressed because it is too large Load Diff

@ -29,6 +29,7 @@
},
"devDependencies": {
"@electron/rebuild": "^3.2.13",
"@types/byline": "^4.2.35",
"cross-env": "^7.0.3",
"electron": "^25.0.1",
"electron-builder": "^23.6.0",
@ -40,7 +41,8 @@
"@remixproject/engine-electron": "0.3.37",
"@remixproject/plugin": "0.3.37",
"@remixproject/plugin-electron": "0.3.37",
"@vscode/ripgrep": "^1.15.4",
"@vscode/ripgrep": "^1.15.6",
"byline": "^5.0.0",
"chokidar": "^3.5.3",
"glob": "9.3.5",
"isomorphic-git": "^1.24.2",

@ -7,6 +7,7 @@ import git from 'isomorphic-git'
import { IsoGitPlugin } from './plugins/isoGitPlugin';
import { ConfigPlugin } from './plugins/configPlugin';
import { TemplatesPlugin } from './plugins/templates';
import { RipgrepPlugin } from './plugins/ripgrepPlugin';
const engine = new Engine()
const appManager = new PluginManager()
@ -15,17 +16,18 @@ const xtermPlugin = new XtermPlugin()
const isoGitPlugin = new IsoGitPlugin()
const configPlugin = new ConfigPlugin()
const templatesPlugin = new TemplatesPlugin()
const ripgrepPlugin = new RipgrepPlugin()
engine.register(appManager)
engine.register(fsPlugin)
engine.register(xtermPlugin)
engine.register(isoGitPlugin)
engine.register(configPlugin)
engine.register(templatesPlugin)
engine.register(ripgrepPlugin)
appManager.activatePlugin('electronconfig')
appManager.activatePlugin('fs')
ipcMain.handle('manager:activatePlugin', async (event, plugin) => {
return await appManager.call(plugin, 'createClient', event.sender.id)
})

@ -7,7 +7,11 @@ import { createWindow, isPackaged } from "../main";
import { writeConfig } from "../utils/config";
import { glob, GlobOptions } from 'glob'
import { Path } from 'path-scurry'
import {rgPath} from '@vscode/ripgrep'
import byline from 'byline';
import path from "path";
import { spawn } from "child_process";
const profile: Profile = {
displayName: 'fs',
@ -82,7 +86,7 @@ const clientProfile: Profile = {
name: 'fs',
displayName: 'fs',
description: 'fs',
methods: ['readdir', 'readFile', 'writeFile', 'mkdir', 'rmdir', 'unlink', 'rename', 'stat', 'lstat', 'exists', 'currentPath', 'watch', 'closeWatch', 'setWorkingDir', 'openFolder', 'openFolderInSameWindow', 'getRecentFolders', 'removeRecentFolder', 'glob', 'openWindow', 'selectFolder']
methods: ['readdir', 'readFile', 'writeFile', 'mkdir', 'rmdir', 'unlink', 'rename', 'stat', 'lstat', 'exists', 'currentPath', 'watch', 'closeWatch', 'setWorkingDir', 'openFolder', 'openFolderInSameWindow', 'getRecentFolders', 'removeRecentFolder', 'openWindow', 'selectFolder']
}
class FSPluginClient extends ElectronBasePluginClient {
@ -93,14 +97,13 @@ class FSPluginClient extends ElectronBasePluginClient {
constructor(webContentsId: number, profile: Profile) {
super(webContentsId, profile)
this.onload(() => {
if(!isPackaged) {
if (!isPackaged) {
this.window.webContents.openDevTools()
}
this.window.on('close', async () => {
await this.removeFromOpenedFolders(this.workingDir)
await this.closeWatch()
})
})
}
@ -110,7 +113,7 @@ class FSPluginClient extends ElectronBasePluginClient {
if (!path) return []
const startTime = Date.now()
const files = await fs.readdir(this.fixPath(path), {
withFileTypes: true
withFileTypes: true,
})
const result: any[] = []
@ -118,36 +121,7 @@ class FSPluginClient extends ElectronBasePluginClient {
const isDirectory = file.isDirectory()
result.push({
file: file.name,
isDirectory
})
}
return result
}
async glob(path: string, pattern: string, options?: GlobOptions): Promise<string[] | Path[]> {
path = convertPathToPosix(this.fixPath(path))
const files = await glob(path + pattern, {
withFileTypes: true,
...options
})
const result: any[] = []
for (const file of files) {
let pathWithoutWorkingDir = (file as Path).path.replace(this.workingDir, '')
if (!pathWithoutWorkingDir.endsWith('/')) {
pathWithoutWorkingDir = pathWithoutWorkingDir + '/'
}
if (pathWithoutWorkingDir.startsWith('/')) {
pathWithoutWorkingDir = pathWithoutWorkingDir.slice(1)
}
if(pathWithoutWorkingDir.startsWith('\\')) {
pathWithoutWorkingDir = pathWithoutWorkingDir.slice(1)
}
result.push({
path: pathWithoutWorkingDir + (file as Path).name,
isDirectory: (file as Path).isDirectory(),
isDirectory,
})
}
return result
@ -174,7 +148,7 @@ class FSPluginClient extends ElectronBasePluginClient {
async rmdir(path: string): Promise<void> {
return fs.rm(this.fixPath(path), {
recursive: true
recursive: true,
})
}
@ -192,7 +166,7 @@ class FSPluginClient extends ElectronBasePluginClient {
const isDirectory = stat.isDirectory()
return {
...stat,
isDirectoryValue: isDirectory
isDirectoryValue: isDirectory,
}
} catch (e) {
return undefined
@ -205,17 +179,18 @@ class FSPluginClient extends ElectronBasePluginClient {
const isDirectory = stat.isDirectory()
return {
...stat,
isDirectoryValue: isDirectory
isDirectoryValue: isDirectory,
}
} catch (e) {
return undefined
}
}
async exists(path: string): Promise<boolean> {
return fs.access(this.fixPath(path)).then(() => true).catch(() => false)
return fs
.access(this.fixPath(path))
.then(() => true)
.catch(() => false)
}
async currentPath(): Promise<string> {
@ -224,16 +199,16 @@ class FSPluginClient extends ElectronBasePluginClient {
async watch(): Promise<void> {
if (this.watcher) this.watcher.close()
this.watcher =
chokidar.watch(this.workingDir, {
ignorePermissionErrors: true, ignoreInitial: true,
this.watcher = chokidar
.watch(this.workingDir, {
ignorePermissionErrors: true,
ignoreInitial: true,
ignored: [
'**/node_modules/**',
'**/.git/index.lock', // this file is created and unlinked all the time when git is running on Windows
]
}).on('all', async (eventName, path, stats) => {
'**/.git/index.lock', // this file is created and unlinked all the time when git is running on Windows
],
})
.on('all', async (eventName, path, stats) => {
let pathWithoutPrefix = path.replace(this.workingDir, '')
pathWithoutPrefix = convertPathToPosix(pathWithoutPrefix)
if (pathWithoutPrefix.startsWith('/')) pathWithoutPrefix = pathWithoutPrefix.slice(1)
@ -243,7 +218,7 @@ class FSPluginClient extends ElectronBasePluginClient {
const newContent = await fs.readFile(path, 'utf-8')
const currentContent = this.trackDownStreamUpdate[pathWithoutPrefix]
if (currentContent !== newContent) {
try {
this.emit('change', eventName, pathWithoutPrefix)
@ -253,7 +228,6 @@ class FSPluginClient extends ElectronBasePluginClient {
}
} else {
try {
this.emit('change', eventName, pathWithoutPrefix)
} catch (e) {
console.log('error emitting change', e)
@ -301,12 +275,11 @@ class FSPluginClient extends ElectronBasePluginClient {
writeConfig(config)
}
async selectFolder(path?: string): Promise<string> {
let dirs: string[] | undefined
if (!path) {
dirs = dialog.showOpenDialogSync(this.window, {
properties: ['openDirectory', 'createDirectory', "showHiddenFiles"]
properties: ['openDirectory', 'createDirectory', 'showHiddenFiles'],
})
}
path = dirs && dirs.length && dirs[0] ? dirs[0] : path
@ -314,13 +287,11 @@ class FSPluginClient extends ElectronBasePluginClient {
return path
}
async openFolder(path?: string): Promise<void> {
let dirs: string[] | undefined
if (!path) {
dirs = dialog.showOpenDialogSync(this.window, {
properties: ['openDirectory', 'createDirectory', "showHiddenFiles"]
properties: ['openDirectory', 'createDirectory', 'showHiddenFiles'],
})
}
path = dirs && dirs.length && dirs[0] ? dirs[0] : path
@ -335,7 +306,7 @@ class FSPluginClient extends ElectronBasePluginClient {
let dirs: string[] | undefined
if (!path) {
dirs = dialog.showOpenDialogSync(this.window, {
properties: ['openDirectory', 'createDirectory', "showHiddenFiles"]
properties: ['openDirectory', 'createDirectory', 'showHiddenFiles'],
})
}
path = dirs && dirs.length && dirs[0] ? dirs[0] : path
@ -372,6 +343,4 @@ class FSPluginClient extends ElectronBasePluginClient {
openWindow(path: string): void {
createWindow(path)
}
}

@ -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
}
}

@ -6,7 +6,7 @@ console.log('preload.ts')
/* preload script needs statically defined API for each plugin */
const exposedPLugins = ['fs', 'git', 'xterm', 'isogit', 'electronconfig', 'electronTemplates']
const exposedPLugins = ['fs', 'git', 'xterm', 'isogit', 'electronconfig', 'electronTemplates', 'ripgrep']
let webContentsId: number | undefined

File diff suppressed because it is too large Load Diff

@ -8,7 +8,7 @@ export const getDirectory = async (dir: string, plugin: any) => {
if (isElectron()) {
const files = await plugin.call('fs', 'glob', dir, '**/*')
const files = await plugin.call('ripgrep', 'glob', dir, '**/*')
// only get path property of files
result = files.map(x => x.path)
} else {

Loading…
Cancel
Save