fix globbing

flattentree
filip mertens 11 months ago
parent fe40d7a616
commit 3fd165a15b
  1. 54
      apps/remix-ide/src/app/plugins/parser/code-parser.tsx
  2. 13
      apps/remix-ide/src/app/plugins/parser/services/code-parser-imports.ts
  3. 18
      apps/remixdesktop/src/plugins/fsPlugin.ts
  4. 4
      apps/remixdesktop/src/plugins/ripgrepPlugin.ts
  5. 4
      apps/remixdesktop/src/utils/config.ts
  6. 2
      libs/remix-ui/search/src/lib/components/results/SearchHelper.ts
  7. 33
      libs/remix-ui/search/src/lib/context/context.tsx

@ -1,14 +1,14 @@
'use strict'
import {Plugin} from '@remixproject/engine'
import {sourceMappingDecoder} from '@remix-project/remix-debug'
import {CompilerAbstract} from '@remix-project/remix-solidity'
import {CompilationResult} from '@remix-project/remix-solidity'
import { Plugin } from '@remixproject/engine'
import { sourceMappingDecoder } from '@remix-project/remix-debug'
import { CompilerAbstract } from '@remix-project/remix-solidity'
import { CompilationResult } from '@remix-project/remix-solidity'
import CodeParserGasService from './services/code-parser-gas-service'
import CodeParserCompiler from './services/code-parser-compiler'
import CodeParserAntlrService from './services/code-parser-antlr-service'
import CodeParserImports, {CodeParserImportsData} from './services/code-parser-imports'
import CodeParserImports, { CodeParserImportsData } from './services/code-parser-imports'
import React from 'react'
import {Profile} from '@remixproject/plugin-utils'
import { Profile } from '@remixproject/plugin-utils'
import {
ContractDefinitionAstNode,
EventDefinitionAstNode,
@ -21,9 +21,9 @@ import {
StructDefinitionAstNode,
VariableDeclarationAstNode
} from '@remix-project/remix-analyzer'
import {lastCompilationResult, RemixApi} from '@remixproject/plugin-api'
import {antlr} from './types'
import {ParseResult} from './types/antlr-types'
import { lastCompilationResult, RemixApi } from '@remixproject/plugin-api'
import { antlr } from './types'
import { ParseResult } from './types/antlr-types'
const profile: Profile = {
name: 'codeParser',
@ -169,20 +169,14 @@ export class CodeParser extends Plugin {
this.on('filePanel', 'setWorkspace', async () => {
await this.call('fileDecorator', 'clearFileDecorators')
setTimeout(async () => {
await this.importService.setFileTree()}
, 3000)
await this.importService.updateDirectoryCacheTimeStamp()
})
this.on('fileManager', 'fileAdded', async () => {
setTimeout(async () => {
await this.importService.setFileTree()}
, 3000)
await this.importService.updateDirectoryCacheTimeStamp()
})
this.on('fileManager', 'fileRemoved', async () => {
setTimeout(async () => {
await this.importService.setFileTree()}
, 3000)
await this.importService.updateDirectoryCacheTimeStamp()
})
this.on('fileManager', 'currentFileChanged', async () => {
@ -199,17 +193,17 @@ export class CodeParser extends Plugin {
})
this.on('config', 'configChanged', async (config) => {
if (config.key === 'settings/auto-completion' ||
config.key === 'settings/display-errors' ||
config.key === 'settings/show-gas') {
if (config.key === 'settings/auto-completion' ||
config.key === 'settings/display-errors' ||
config.key === 'settings/show-gas') {
await this.reload()
}
})
this.on('settings', 'configChanged', async (config) => {
if (config.key === 'settings/auto-completion' ||
config.key === 'settings/display-errors' ||
config.key === 'settings/show-gas') {
if (config.key === 'settings/auto-completion' ||
config.key === 'settings/display-errors' ||
config.key === 'settings/show-gas') {
await this.reload()
}
})
@ -382,7 +376,7 @@ export class CodeParser extends Plugin {
} else if (visibility === 'private' || visibility === 'internal') {
executionCost = estimationObj === null ? '-' : estimationObj.internal[fn]
}
return {executionCost}
return { executionCost }
} else {
return {
creationCost: estimationObj === null ? '-' : estimationObj.creation.totalCost,
@ -538,9 +532,9 @@ export class CodeParser extends Plugin {
if (nodeDefinition.ast && nodeDefinition.parser) {
if (nodeDefinition.ast.name === nodeDefinition.parser.name && nodeDefinition.ast.nodeType === nodeDefinition.parser.type) {
return nodeDefinition.ast
}else{
} else {
// if there is a difference and the compiler has compiled correctly assume the ast node is the definition
if(this.compilerService.errorState === false){
if (this.compilerService.errorState === false) {
return nodeDefinition.ast
}
}
@ -716,9 +710,9 @@ export class CodeParser extends Plugin {
async getNodeDocumentation(node: genericASTNode) {
if ('documentation' in node && node.documentation && (node.documentation as any).text) {
let text = ''
;(node.documentation as any).text.split('\n').forEach((line) => {
text += `${line.trim()}\n`
})
; (node.documentation as any).text.split('\n').forEach((line) => {
text += `${line.trim()}\n`
})
return text
}
}

@ -6,18 +6,23 @@ export type CodeParserImportsData = {
files?: string[],
modules?: string[],
packages?: string[],
timestamp?: number
}
export default class CodeParserImports {
plugin: CodeParser
data: CodeParserImportsData = {}
directoryUpdateCacheTimeStamp = 0
constructor(plugin: CodeParser) {
this.plugin = plugin
this.init()
}
async getImports(){
if(!this.data || !this.data.files || !this.data.timestamp || this.data.timestamp != this.directoryUpdateCacheTimeStamp){
await this.setFileTree()
}
return this.data
}
@ -39,13 +44,17 @@ export default class CodeParserImports {
this.data.packages = [...new Set(this.data.modules.map(x => x.split('/')[0]))]
}
updateDirectoryCacheTimeStamp = async () => {
this.directoryUpdateCacheTimeStamp = Date.now()
}
setFileTree = async () => {
if (Registry.getInstance().get('platform').api.isDesktop()) {
const search = {
path: '/',
include: ['**/*.sol', '**/*.vy', '**/*.py'],
exclude: [],
pattern: ['.'],
pattern: [],
matchCase: false,
useRegExp: false,
matchWholeWord: false,
@ -53,13 +62,13 @@ export default class CodeParserImports {
}
const files = await this.plugin.call('ripgrep', 'glob', search)
// only get path property of files
this.data.files = files.map((x) => x.path)
} else {
this.data.files = await this.getDirectory('/')
this.data.files = this.data.files.filter((x) => x.endsWith('.sol') && !x.startsWith('.deps') && !x.startsWith('.git'))
}
this.data.timestamp = this.directoryUpdateCacheTimeStamp || Date.now()
}
getDirectory = async (dir: string) => {

@ -105,7 +105,7 @@ class FSPluginClient extends ElectronBasePluginClient {
})
this.dataBatcher = new PluginEventDataBatcher(webContentsId)
this.dataBatcher.on('flush', (data: any) => {
console.log('flush', data)
//console.log('flush', data)
this.emit('eventGroup', data)
})
}
@ -206,14 +206,14 @@ class FSPluginClient extends ElectronBasePluginClient {
try {
this.off('filePanel' as any, 'expandPathChanged')
this.on('filePanel' as any, 'expandPathChanged', async (paths: string[]) => {
console.log('expandPathChanged', paths)
//console.log('expandPathChanged', paths)
this.expandedPaths = ['.', ...paths] // add root
console.log(Object.keys(this.watchers))
//console.log(Object.keys(this.watchers))
paths = paths.map((path) => this.fixPath(path))
for (const path of paths) {
if (!Object.keys(this.watchers).includes(path)) {
this.watchers[path] = await this.watcherInit(path)
console.log('added watcher', path)
//console.log('added watcher', path)
}
}
@ -222,12 +222,12 @@ class FSPluginClient extends ElectronBasePluginClient {
if (!paths.includes(watcher)) {
await this.watchers[watcher].close()
delete this.watchers[watcher]
console.log('removed watcher', watcher)
//console.log('removed watcher', watcher)
}
}
})
this.watchers[this.workingDir] = await this.watcherInit(this.workingDir) // root
console.log('added root watcher', this.workingDir)
//console.log('added root watcher', this.workingDir)
} catch (e) {
console.log('error watching', e)
}
@ -271,7 +271,7 @@ class FSPluginClient extends ElectronBasePluginClient {
try {
const dirname = path.dirname(pathWithoutPrefix)
if (this.expandedPaths.includes(dirname) || this.expandedPaths.includes(pathWithoutPrefix)) {
console.log('emitting', eventName, pathWithoutPrefix, this.expandedPaths)
//console.log('emitting', eventName, pathWithoutPrefix, this.expandedPaths)
this.dataBatcher.write('change', eventName, pathWithoutPrefix)
}
} catch (e) {
@ -281,9 +281,9 @@ class FSPluginClient extends ElectronBasePluginClient {
} else {
try {
const dirname = path.dirname(pathWithoutPrefix)
console.log('check emitting', eventName, pathWithoutPrefix, this.expandedPaths, dirname)
//console.log('check emitting', eventName, pathWithoutPrefix, this.expandedPaths, dirname)
if (this.expandedPaths.includes(dirname) || this.expandedPaths.includes(pathWithoutPrefix)) {
console.log('emitting', eventName, pathWithoutPrefix, this.expandedPaths)
//console.log('emitting', eventName, pathWithoutPrefix, this.expandedPaths)
//this.emit('change', eventName, pathWithoutPrefix)
this.dataBatcher.write('change', eventName, pathWithoutPrefix)
}

@ -68,14 +68,14 @@ export class RipgrepPluginClient extends ElectronBasePluginClient {
if (opts && opts.include) {
for (const include of opts.include) {
if (include !== '') {
globs.push('--glob=**/' + include)
globs.push('--glob=' + include)
}
}
}
if (opts && opts.exclude) {
for (const exclude of opts.exclude) {
if (exclude !== '') {
globs.push('--glob=!**/' + exclude)
globs.push('--glob=!=' + exclude)
}
}
}

@ -27,7 +27,7 @@ export const writeConfig = async (data: any) => {
await createDefaultConfigLocations()
const cache = readConfig()
try {
console.log('write config file', data)
//console.log('write config file', data)
fs.writeFileSync(cacheDir + '/remixdesktop.json', JSON.stringify({ ...cache, ...data }))
} catch (e) {
console.error('Can\'t write config file', e)
@ -41,7 +41,7 @@ export const readConfig = async () => {
// read the cache file
const cache = fs.readFileSync(cacheDir + '/remixdesktop.json')
const data = JSON.parse(cache.toString())
console.log('read config file', data)
//console.log('read config file', data)
return data
} catch (e) {
console.error('Can\'t read config file', e)

@ -5,12 +5,10 @@ import {Registry} from '@remix-project/remix-lib'
export const getDirectory = async (dir: string, plugin: any) => {
let result = []
if (Registry.getInstance().get('platform').api.isDesktop()) {
// only get path property of files
result = []
} else {
const files = await plugin.call('fileManager', 'readdir', dir)
const fileArray = normalize(files)
for (const fi of fileArray) {

@ -39,8 +39,12 @@ export const SearchContext = createContext<SearchingStateInterface>(null)
export const SearchProvider = ({ children = [], reducer = SearchReducer, initialState = SearchingInitialState, plugin = undefined, platform = undefined } = {}) => {
const [state, dispatch] = useReducer(reducer, initialState)
const [files, setFiles] = useState([])
const [files, setFiles] = useState<{
files: string[],
timeStamp: number
}>(null)
const clearSearchingTimeout = useRef(null)
const directoryUpdateCacheTimeStamp = useRef<number>(0)
const value = {
state,
setFind: (value: string) => {
@ -266,10 +270,8 @@ export const SearchProvider = ({ children = [], reducer = SearchReducer, initial
await value.reloadFile(file)
}
const updateFiles = async () => {
setTimeout(async () => {
setFiles(await getDirectory('/', plugin))
}, 2000)
const updateDirectoryCacheTimeStamp = async () => {
directoryUpdateCacheTimeStamp.current = Date.now()
}
useEffect(() => {
@ -277,7 +279,7 @@ export const SearchProvider = ({ children = [], reducer = SearchReducer, initial
value.setSearchResults(null)
value.clearUndo()
value.setCurrentWorkspace(workspace.name)
await updateFiles()
await updateDirectoryCacheTimeStamp()
})
plugin.on('fileManager', 'fileSaved', async (file) => {
await reloadStateForFile(file)
@ -286,15 +288,15 @@ export const SearchProvider = ({ children = [], reducer = SearchReducer, initial
plugin.on('fileManager', 'rootFolderChanged', async (file) => {
const workspace = await plugin.call('filePanel', 'getCurrentWorkspace')
if (workspace) value.setCurrentWorkspace(workspace.name)
await updateFiles()
await updateDirectoryCacheTimeStamp()
})
plugin.on('fs', 'workingDirChanged', async () => {
await updateFiles()
await updateDirectoryCacheTimeStamp()
})
plugin.on('fileManager', 'fileAdded', async (file) => {
await updateFiles()
await updateDirectoryCacheTimeStamp()
await reloadStateForFile(file)
})
plugin.on('fileManager', 'currentFileChanged', async (file) => {
@ -306,7 +308,7 @@ export const SearchProvider = ({ children = [], reducer = SearchReducer, initial
const workspace = await plugin.call('filePanel', 'getCurrentWorkspace')
if (workspace && workspace.name) {
value.setCurrentWorkspace(workspace.name)
await updateFiles()
await updateDirectoryCacheTimeStamp()
}
} catch (e) {
console.log(e)
@ -413,7 +415,16 @@ export const SearchProvider = ({ children = [], reducer = SearchReducer, initial
})
value.setSearchResults(filteredFiles)
} else {
const filteredFiles = files.filter(filePathFilter(pathFilter)).map((file) => {
let filesToSearch = files?.files
if(!files || files.timeStamp != directoryUpdateCacheTimeStamp.current) {
const newFiles = await getDirectory('/', plugin)
setFiles({
files: newFiles,
timeStamp: directoryUpdateCacheTimeStamp.current || Date.now()
})
filesToSearch = newFiles
}
const filteredFiles = filesToSearch.filter(filePathFilter(pathFilter)).map((file) => {
const r: SearchResult = {
filename: file,
lines: [],

Loading…
Cancel
Save