search update

pull/4346/head
filip mertens 11 months ago
parent 78230cab83
commit 57ffea12fc
  1. 12
      apps/remix-ide/src/app/plugins/parser/services/code-parser-imports.ts
  2. 33
      apps/remixdesktop/src/lib/index.ts
  3. 1
      apps/remixdesktop/src/plugins/fsPlugin.ts
  4. 42
      apps/remixdesktop/src/plugins/ripgrepPlugin.ts
  5. 138
      apps/remixdesktop/yarn.lock
  6. 4
      libs/remix-ui/search/src/lib/components/Search.tsx
  7. 4
      libs/remix-ui/search/src/lib/components/results/SearchHelper.ts
  8. 72
      libs/remix-ui/search/src/lib/context/context.tsx
  9. 35
      libs/remix-ui/search/src/lib/types/index.ts
  10. 1
      libs/remix-ui/workspace/src/lib/actions/events.ts

@ -41,7 +41,17 @@ export default class CodeParserImports {
setFileTree = async () => {
if (Registry.getInstance().get('platform').api.isDesktop()) {
const files = await this.plugin.call('ripgrep', 'glob', '/', '**/*.sol')
const search = {
path: '/',
include: ['**/*.sol', '**/*.vy', '**/*.py'],
exclude: [],
pattern: ['.'],
matchCase: false,
useRegExp: false,
matchWholeWord: false,
maxResults: 10000
}
const files = await this.plugin.call('ripgrep', 'glob', search)
// only get path property of files
this.data.files = files.map((x) => x.path)
} else {

@ -14,3 +14,36 @@ export const stripAnsi = (string: string) => {
}
return string.replace(regex, '');
}
export interface SearchInWorkspaceOptions {
pattern: string
path: string
/**
* Maximum number of results to return. Defaults to unlimited.
*/
maxResults?: number
/**
* Search case sensitively if true.
*/
matchCase?: boolean
/**
* Search whole words only if true.
*/
matchWholeWord?: boolean
/**
* Use regular expressions for search if true.
*/
useRegExp?: boolean
/**
* Include all .gitignored and hidden files.
*/
includeIgnored?: boolean
/**
* Glob pattern for matching files and directories to include the search.
*/
include?: string[]
/**
* Glob pattern for matching files and directories to exclude the search.
*/
exclude?: string[]
}

@ -212,7 +212,6 @@ class FSPluginClient extends ElectronBasePluginClient {
let pathWithoutPrefix = path.replace(this.workingDir, '')
pathWithoutPrefix = convertPathToPosix(pathWithoutPrefix)
if (pathWithoutPrefix.startsWith('/')) pathWithoutPrefix = pathWithoutPrefix.slice(1)
console.log('eventName', eventName, pathWithoutPrefix)
if (eventName === 'change') {
// remove workingDir from path
const newContent = await fs.readFile(path, 'utf-8')

@ -5,6 +5,7 @@ import path from 'path'
import {rgPath} from '@vscode/ripgrep'
import byline from 'byline'
import {spawn} from 'child_process'
import { SearchInWorkspaceOptions } from '../lib'
const profile: Profile = {
name: 'ripgrep',
@ -31,6 +32,19 @@ const clientProfile: Profile = {
methods: ['glob'],
}
const getArgs = (options?: SearchInWorkspaceOptions) => {
const args = ['-l']
args.push(options && options.matchCase ? '--case-sensitive' : '--ignore-case')
if (options && options.matchWholeWord) {
args.push('--word-regexp')
}
if (options && options.includeIgnored) {
args.push('-uu')
}
args.push(options && options.useRegExp ? '--regexp' : '--fixed-strings')
return args
}
export class RipgrepPluginClient extends ElectronBasePluginClient {
workingDir: string = ''
constructor(webContentsId: number, profile: Profile) {
@ -43,17 +57,35 @@ export class RipgrepPluginClient extends ElectronBasePluginClient {
})
}
async glob(path: string, pattern: string, options?: any) {
async glob(opts: SearchInWorkspaceOptions) {
try {
const fixedPath = this.fixPath(path)
path = convertPathToPosix(fixedPath)
opts = JSON.parse(JSON.stringify(opts))
const fixedPath = this.fixPath(opts.path)
const path = convertPathToPosix(fixedPath)
const args = getArgs(opts)
const globs: string[] = []
if (opts && opts.include) {
for (const include of opts.include) {
if (include !== '') {
globs.push('--glob=**/' + include)
}
}
}
if (opts && opts.exclude) {
for (const exclude of opts.exclude) {
if (exclude !== '') {
globs.push('--glob=!**/' + exclude)
}
}
}
return new Promise((c, e) => {
// replace packed app path with unpacked app path for release on windows
const customRgPath = rgPath.includes('app.asar.unpacked') ? rgPath : rgPath.replace('app.asar', 'app.asar.unpacked')
console.log('customRgPath', customRgPath, path)
const rg = spawn(customRgPath, ['.', '-l', path])
const rg = spawn(customRgPath, [...globs, ...args, opts.pattern, path])
const resultrg: any[] = []

@ -87,116 +87,6 @@
dependencies:
"@babel/runtime" "^7.8.3"
"@esbuild/android-arm64@0.19.5":
version "0.19.5"
resolved "https://registry.yarnpkg.com/@esbuild/android-arm64/-/android-arm64-0.19.5.tgz#276c5f99604054d3dbb733577e09adae944baa90"
integrity sha512-5d1OkoJxnYQfmC+Zd8NBFjkhyCNYwM4n9ODrycTFY6Jk1IGiZ+tjVJDDSwDt77nK+tfpGP4T50iMtVi4dEGzhQ==
"@esbuild/android-arm@0.19.5":
version "0.19.5"
resolved "https://registry.yarnpkg.com/@esbuild/android-arm/-/android-arm-0.19.5.tgz#4a3cbf14758166abaae8ba9c01a80e68342a4eec"
integrity sha512-bhvbzWFF3CwMs5tbjf3ObfGqbl/17ict2/uwOSfr3wmxDE6VdS2GqY/FuzIPe0q0bdhj65zQsvqfArI9MY6+AA==
"@esbuild/android-x64@0.19.5":
version "0.19.5"
resolved "https://registry.yarnpkg.com/@esbuild/android-x64/-/android-x64-0.19.5.tgz#21a3d11cd4613d2d3c5ccb9e746c254eb9265b0a"
integrity sha512-9t+28jHGL7uBdkBjL90QFxe7DVA+KGqWlHCF8ChTKyaKO//VLuoBricQCgwhOjA1/qOczsw843Fy4cbs4H3DVA==
"@esbuild/darwin-arm64@0.19.5":
version "0.19.5"
resolved "https://registry.yarnpkg.com/@esbuild/darwin-arm64/-/darwin-arm64-0.19.5.tgz#714cb839f467d6a67b151ee8255886498e2b9bf6"
integrity sha512-mvXGcKqqIqyKoxq26qEDPHJuBYUA5KizJncKOAf9eJQez+L9O+KfvNFu6nl7SCZ/gFb2QPaRqqmG0doSWlgkqw==
"@esbuild/darwin-x64@0.19.5":
version "0.19.5"
resolved "https://registry.yarnpkg.com/@esbuild/darwin-x64/-/darwin-x64-0.19.5.tgz#2c553e97a6d2b4ae76a884e35e6cbab85a990bbf"
integrity sha512-Ly8cn6fGLNet19s0X4unjcniX24I0RqjPv+kurpXabZYSXGM4Pwpmf85WHJN3lAgB8GSth7s5A0r856S+4DyiA==
"@esbuild/freebsd-arm64@0.19.5":
version "0.19.5"
resolved "https://registry.yarnpkg.com/@esbuild/freebsd-arm64/-/freebsd-arm64-0.19.5.tgz#d554f556718adb31917a0da24277bf84b6ee87f3"
integrity sha512-GGDNnPWTmWE+DMchq1W8Sd0mUkL+APvJg3b11klSGUDvRXh70JqLAO56tubmq1s2cgpVCSKYywEiKBfju8JztQ==
"@esbuild/freebsd-x64@0.19.5":
version "0.19.5"
resolved "https://registry.yarnpkg.com/@esbuild/freebsd-x64/-/freebsd-x64-0.19.5.tgz#288f7358a3bb15d99e73c65c9adaa3dabb497432"
integrity sha512-1CCwDHnSSoA0HNwdfoNY0jLfJpd7ygaLAp5EHFos3VWJCRX9DMwWODf96s9TSse39Br7oOTLryRVmBoFwXbuuQ==
"@esbuild/linux-arm64@0.19.5":
version "0.19.5"
resolved "https://registry.yarnpkg.com/@esbuild/linux-arm64/-/linux-arm64-0.19.5.tgz#95933ae86325c93cb6b5e8333d22120ecfdc901b"
integrity sha512-o3vYippBmSrjjQUCEEiTZ2l+4yC0pVJD/Dl57WfPwwlvFkrxoSO7rmBZFii6kQB3Wrn/6GwJUPLU5t52eq2meA==
"@esbuild/linux-arm@0.19.5":
version "0.19.5"
resolved "https://registry.yarnpkg.com/@esbuild/linux-arm/-/linux-arm-0.19.5.tgz#0acef93aa3e0579e46d33b666627bddb06636664"
integrity sha512-lrWXLY/vJBzCPC51QN0HM71uWgIEpGSjSZZADQhq7DKhPcI6NH1IdzjfHkDQws2oNpJKpR13kv7/pFHBbDQDwQ==
"@esbuild/linux-ia32@0.19.5":
version "0.19.5"
resolved "https://registry.yarnpkg.com/@esbuild/linux-ia32/-/linux-ia32-0.19.5.tgz#b6e5c9e80b42131cbd6b1ddaa48c92835f1ed67f"
integrity sha512-MkjHXS03AXAkNp1KKkhSKPOCYztRtK+KXDNkBa6P78F8Bw0ynknCSClO/ztGszILZtyO/lVKpa7MolbBZ6oJtQ==
"@esbuild/linux-loong64@0.19.5":
version "0.19.5"
resolved "https://registry.yarnpkg.com/@esbuild/linux-loong64/-/linux-loong64-0.19.5.tgz#e5f0cf95a180158b01ff5f417da796a1c09dfbea"
integrity sha512-42GwZMm5oYOD/JHqHska3Jg0r+XFb/fdZRX+WjADm3nLWLcIsN27YKtqxzQmGNJgu0AyXg4HtcSK9HuOk3v1Dw==
"@esbuild/linux-mips64el@0.19.5":
version "0.19.5"
resolved "https://registry.yarnpkg.com/@esbuild/linux-mips64el/-/linux-mips64el-0.19.5.tgz#ae36fb86c7d5f641f3a0c8472e83dcb6ea36a408"
integrity sha512-kcjndCSMitUuPJobWCnwQ9lLjiLZUR3QLQmlgaBfMX23UEa7ZOrtufnRds+6WZtIS9HdTXqND4yH8NLoVVIkcg==
"@esbuild/linux-ppc64@0.19.5":
version "0.19.5"
resolved "https://registry.yarnpkg.com/@esbuild/linux-ppc64/-/linux-ppc64-0.19.5.tgz#7960cb1666f0340ddd9eef7b26dcea3835d472d0"
integrity sha512-yJAxJfHVm0ZbsiljbtFFP1BQKLc8kUF6+17tjQ78QjqjAQDnhULWiTA6u0FCDmYT1oOKS9PzZ2z0aBI+Mcyj7Q==
"@esbuild/linux-riscv64@0.19.5":
version "0.19.5"
resolved "https://registry.yarnpkg.com/@esbuild/linux-riscv64/-/linux-riscv64-0.19.5.tgz#32207df26af60a3a9feea1783fc21b9817bade19"
integrity sha512-5u8cIR/t3gaD6ad3wNt1MNRstAZO+aNyBxu2We8X31bA8XUNyamTVQwLDA1SLoPCUehNCymhBhK3Qim1433Zag==
"@esbuild/linux-s390x@0.19.5":
version "0.19.5"
resolved "https://registry.yarnpkg.com/@esbuild/linux-s390x/-/linux-s390x-0.19.5.tgz#b38d5681db89a3723862dfa792812397b1510a7d"
integrity sha512-Z6JrMyEw/EmZBD/OFEFpb+gao9xJ59ATsoTNlj39jVBbXqoZm4Xntu6wVmGPB/OATi1uk/DB+yeDPv2E8PqZGw==
"@esbuild/linux-x64@0.19.5":
version "0.19.5"
resolved "https://registry.yarnpkg.com/@esbuild/linux-x64/-/linux-x64-0.19.5.tgz#46feba2ad041a241379d150f415b472fe3885075"
integrity sha512-psagl+2RlK1z8zWZOmVdImisMtrUxvwereIdyJTmtmHahJTKb64pAcqoPlx6CewPdvGvUKe2Jw+0Z/0qhSbG1A==
"@esbuild/netbsd-x64@0.19.5":
version "0.19.5"
resolved "https://registry.yarnpkg.com/@esbuild/netbsd-x64/-/netbsd-x64-0.19.5.tgz#3b5c1fb068f26bfc681d31f682adf1bea4ef0702"
integrity sha512-kL2l+xScnAy/E/3119OggX8SrWyBEcqAh8aOY1gr4gPvw76la2GlD4Ymf832UCVbmuWeTf2adkZDK+h0Z/fB4g==
"@esbuild/openbsd-x64@0.19.5":
version "0.19.5"
resolved "https://registry.yarnpkg.com/@esbuild/openbsd-x64/-/openbsd-x64-0.19.5.tgz#ca6830316ca68056c5c88a875f103ad3235e00db"
integrity sha512-sPOfhtzFufQfTBgRnE1DIJjzsXukKSvZxloZbkJDG383q0awVAq600pc1nfqBcl0ice/WN9p4qLc39WhBShRTA==
"@esbuild/sunos-x64@0.19.5":
version "0.19.5"
resolved "https://registry.yarnpkg.com/@esbuild/sunos-x64/-/sunos-x64-0.19.5.tgz#9efc4eb9539a7be7d5a05ada52ee43cda0d8e2dd"
integrity sha512-dGZkBXaafuKLpDSjKcB0ax0FL36YXCvJNnztjKV+6CO82tTYVDSH2lifitJ29jxRMoUhgkg9a+VA/B03WK5lcg==
"@esbuild/win32-arm64@0.19.5":
version "0.19.5"
resolved "https://registry.yarnpkg.com/@esbuild/win32-arm64/-/win32-arm64-0.19.5.tgz#29f8184afa7a02a956ebda4ed638099f4b8ff198"
integrity sha512-dWVjD9y03ilhdRQ6Xig1NWNgfLtf2o/STKTS+eZuF90fI2BhbwD6WlaiCGKptlqXlURVB5AUOxUj09LuwKGDTg==
"@esbuild/win32-ia32@0.19.5":
version "0.19.5"
resolved "https://registry.yarnpkg.com/@esbuild/win32-ia32/-/win32-ia32-0.19.5.tgz#f3de07afb292ecad651ae4bb8727789de2d95b05"
integrity sha512-4liggWIA4oDgUxqpZwrDhmEfAH4d0iljanDOK7AnVU89T6CzHon/ony8C5LeOdfgx60x5cnQJFZwEydVlYx4iw==
"@esbuild/win32-x64@0.19.5":
version "0.19.5"
resolved "https://registry.yarnpkg.com/@esbuild/win32-x64/-/win32-x64-0.19.5.tgz#faad84c41ba12e3a0acb52571df9bff37bee75f6"
integrity sha512-czTrygUsB/jlM8qEW5MD8bgYU2Xg14lo6kBDXW6HdxKjh8M5PzETGiSHaz9MtbXBYDloHNUAUW2tMiKW4KM9Mw==
"@ethereumjs/common@2.6.5", "@ethereumjs/common@^2.6.4":
version "2.6.5"
resolved "https://registry.yarnpkg.com/@ethereumjs/common/-/common-2.6.5.tgz#0a75a22a046272579d91919cb12d84f2756e8d30"
@ -2304,34 +2194,6 @@ es6-symbol@^3.1.1, es6-symbol@^3.1.3:
d "^1.0.1"
ext "^1.1.2"
esbuild@^0.19.5:
version "0.19.5"
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.19.5.tgz#53a0e19dfbf61ba6c827d51a80813cf071239a8c"
integrity sha512-bUxalY7b1g8vNhQKdB24QDmHeY4V4tw/s6Ak5z+jJX9laP5MoQseTOMemAr0gxssjNcH0MCViG8ONI2kksvfFQ==
optionalDependencies:
"@esbuild/android-arm" "0.19.5"
"@esbuild/android-arm64" "0.19.5"
"@esbuild/android-x64" "0.19.5"
"@esbuild/darwin-arm64" "0.19.5"
"@esbuild/darwin-x64" "0.19.5"
"@esbuild/freebsd-arm64" "0.19.5"
"@esbuild/freebsd-x64" "0.19.5"
"@esbuild/linux-arm" "0.19.5"
"@esbuild/linux-arm64" "0.19.5"
"@esbuild/linux-ia32" "0.19.5"
"@esbuild/linux-loong64" "0.19.5"
"@esbuild/linux-mips64el" "0.19.5"
"@esbuild/linux-ppc64" "0.19.5"
"@esbuild/linux-riscv64" "0.19.5"
"@esbuild/linux-s390x" "0.19.5"
"@esbuild/linux-x64" "0.19.5"
"@esbuild/netbsd-x64" "0.19.5"
"@esbuild/openbsd-x64" "0.19.5"
"@esbuild/sunos-x64" "0.19.5"
"@esbuild/win32-arm64" "0.19.5"
"@esbuild/win32-ia32" "0.19.5"
"@esbuild/win32-x64" "0.19.5"
escalade@^3.1.1:
version "3.1.1"
resolved "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz"

@ -6,14 +6,16 @@ import {Include} from './Include'
import {Exclude} from './Exclude'
import {FindContainer} from './FindContainer'
import {Undo} from './Undo'
import { AppContext } from '@remix-ui/app'
export const SearchTab = (props) => {
const plugin = props.plugin
const {platform} = useContext(AppContext)
return (
<>
<div className="search_plugin_search_tab pr-4 px-2 pb-4">
<SearchProvider plugin={plugin}>
<SearchProvider platform={platform} plugin={plugin}>
<FindContainer></FindContainer>
<Include></Include>
<Exclude></Exclude>

@ -7,10 +7,8 @@ export const getDirectory = async (dir: string, plugin: any) => {
let result = []
if (Registry.getInstance().get('platform').api.isDesktop()) {
const files = await plugin.call('ripgrep', 'glob', dir, '**/*')
// only get path property of files
result = files.map(x => x.path)
result = []
} else {
const files = await plugin.call('fileManager', 'readdir', dir)

@ -1,10 +1,11 @@
import React, {useEffect, useRef, useState} from 'react'
import {createContext, useReducer} from 'react'
import {findLinesInStringWithMatch, getDirectory, replaceAllInFile, replaceTextInLine} from '../components/results/SearchHelper'
import {SearchReducer} from '../reducers/Reducer'
import {SearchState, SearchResult, SearchResultLine, SearchResultLineLine, SearchingInitialState, undoBufferRecord} from '../types'
import {filePathFilter} from '@jsdevtools/file-path-filter'
import {escapeRegExp} from 'lodash'
import React, { useEffect, useRef, useState } from 'react'
import { createContext, useReducer } from 'react'
import { findLinesInStringWithMatch, getDirectory, replaceAllInFile, replaceTextInLine } from '../components/results/SearchHelper'
import { SearchReducer } from '../reducers/Reducer'
import { SearchState, SearchResult, SearchResultLine, SearchResultLineLine, SearchingInitialState, undoBufferRecord, SearchInWorkspaceOptions } from '../types'
import { filePathFilter } from '@jsdevtools/file-path-filter'
import { escapeRegExp } from 'lodash'
import { appPlatformTypes } from '@remix-ui/app'
export interface SearchingStateInterface {
state: SearchState
@ -36,7 +37,7 @@ export interface SearchingStateInterface {
export const SearchContext = createContext<SearchingStateInterface>(null)
export const SearchProvider = ({children = [], reducer = SearchReducer, initialState = SearchingInitialState, plugin = undefined} = {}) => {
export const SearchProvider = ({ children = [], reducer = SearchReducer, initialState = SearchingInitialState, plugin = undefined, platform = undefined } = {}) => {
const [state, dispatch] = useReducer(reducer, initialState)
const [files, setFiles] = useState([])
const clearSearchingTimeout = useRef(null)
@ -148,7 +149,7 @@ export const SearchProvider = ({children = [], reducer = SearchReducer, initialS
updateCount: (count: number, file: string) => {
dispatch({
type: 'UPDATE_COUNT',
payload: {count, file}
payload: { count, file }
})
},
setSearching(file: string) {
@ -371,7 +372,7 @@ export const SearchProvider = ({children = [], reducer = SearchReducer, initialS
useEffect(() => {
if (state.find) {
;(async () => {
; (async () => {
try {
const pathFilter: any = {}
if (state.include) {
@ -380,18 +381,47 @@ export const SearchProvider = ({children = [], reducer = SearchReducer, initialS
if (state.exclude) {
pathFilter.exclude = setGlobalExpression(state.exclude)
}
const filteredFiles = files.filter(filePathFilter(pathFilter)).map((file) => {
const r: SearchResult = {
filename: file,
lines: [],
path: file,
timeStamp: Date.now(),
forceReload: false,
count: 0
if (platform == appPlatformTypes.desktop) {
const search: SearchInWorkspaceOptions = {
path: '/',
pattern: state.find,
useRegExp: state.useRegExp,
matchCase: state.casesensitive,
matchWholeWord: state.matchWord,
include: pathFilter.include,
exclude: pathFilter.exclude
}
return r
})
value.setSearchResults(filteredFiles)
const filesfromripgrep = await plugin.call('ripgrep', 'glob', search)
const filteredFiles = filesfromripgrep.map((file) => {
const r: SearchResult = {
filename: file.path,
lines: [],
path: file.path,
timeStamp: Date.now(),
forceReload: false,
count: 0
}
return r
})
value.setSearchResults(filteredFiles)
} else {
const filteredFiles = files.filter(filePathFilter(pathFilter)).map((file) => {
const r: SearchResult = {
filename: file,
lines: [],
path: file,
timeStamp: Date.now(),
forceReload: false,
count: 0
}
return r
})
value.setSearchResults(filteredFiles)
}
} catch (e) {
console.log(e)
}

@ -91,3 +91,38 @@ export const SearchingInitialState: SearchState = {
searching: null,
run: false,
}
export interface SearchInWorkspaceOptions {
pattern: string
path: string
/**
* Maximum number of results to return. Defaults to unlimited.
*/
maxResults?: number
/**
* Search case sensitively if true.
*/
matchCase?: boolean
/**
* Search whole words only if true.
*/
matchWholeWord?: boolean
/**
* Use regular expressions for search if true.
*/
useRegExp?: boolean
/**
* Include all .gitignored and hidden files.
*/
includeIgnored?: boolean
/**
* Glob pattern for matching files and directories to include the search.
*/
include?: string[]
/**
* Glob pattern for matching files and directories to exclude the search.
*/
exclude?: string[]
}

@ -178,7 +178,6 @@ const removePluginActions = (plugin, cb: (err: Error, result?: string | number |
const fileAdded = async (filePath: string) => {
if (isElectron()) {
const path = extractParentFromKey(filePath) || ROOT_PATH
console.log('fileAdded', filePath, path)
const isExpanded = await plugin.call('filePanel', 'isExpanded', path)
if (!isExpanded) return

Loading…
Cancel
Save