Skip to content

Commit

Permalink
fix: index known files by default, index other files explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed Mar 3, 2025
1 parent 7220d00 commit 5182a0b
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 56 deletions.
4 changes: 2 additions & 2 deletions app/lib/file-context/file-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ module.exports = class FileContext extends EventEmitter {
/**
* Handle file opened.
*
* @param { { uri: string, value: string } } fileProps
* @param { { uri: string, value: string, processor?: string } } fileProps
*/
fileOpened(fileProps) {
return this._indexer.fileOpened(fileProps);

Check warning on line 112 in app/lib/file-context/file-context.js

View check run for this annotation

Codecov / codecov/patch

app/lib/file-context/file-context.js#L112

Added line #L112 was not covered by tests
Expand All @@ -115,7 +115,7 @@ module.exports = class FileContext extends EventEmitter {
/**
* Handle file content changed.
*
* @param { { uri: string, value: string } } fileProps
* @param { { uri: string, value: string, processor?: string } } fileProps
*/
fileContentChanged(fileProps) {
return this._indexer.fileContentChanged(fileProps);

Check warning on line 121 in app/lib/file-context/file-context.js

View check run for this annotation

Codecov / codecov/patch

app/lib/file-context/file-context.js#L121

Added line #L121 was not covered by tests
Expand Down
26 changes: 15 additions & 11 deletions app/lib/file-context/indexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,17 @@ module.exports = class Indexer {
/**
* @param { string } uri
* @param { string } [localValue]
* @param { string } [processor]
*/
add(uri, localValue) {
add(uri, localValue, processor) {
uri = toFileUrl(uri);

this._logger.info('indexer:add', uri, localValue);
this._logger.info('indexer:add', uri, localValue, processor);

let indexItem = this.items.get(uri);

if (!indexItem) {
indexItem = createIndexItem({ uri, localValue });
indexItem = createIndexItem({ uri, localValue, processor });

this.items.set(uri, indexItem);
}
Expand All @@ -126,35 +127,35 @@ module.exports = class Indexer {
/**
* Notify file opened
*
* @param { { uri: string, value: string } } fileProps
* @param { { uri: string, value: string, processor?: string } } fileProps
*/
fileOpened(fileProps) {

const {
processor,
uri,
value
} = fileProps;

Check warning on line 137 in app/lib/file-context/indexer.js

View check run for this annotation

Codecov / codecov/patch

app/lib/file-context/indexer.js#L137

Added line #L137 was not covered by tests

this._emit('file-opened', uri);

Check warning on line 139 in app/lib/file-context/indexer.js

View check run for this annotation

Codecov / codecov/patch

app/lib/file-context/indexer.js#L139

Added line #L139 was not covered by tests

return this.add(toFileUrl(uri), value);
return this.add(toFileUrl(uri), value, processor);

Check warning on line 141 in app/lib/file-context/indexer.js

View check run for this annotation

Codecov / codecov/patch

app/lib/file-context/indexer.js#L141

Added line #L141 was not covered by tests
}

/**
* Notify file content changed
*
* @param { { uri: string, value: string } } fileProps
* @param { { uri: string, value: string, processor?: string } } fileProps
*/
fileContentChanged(fileProps) {

const {
processor,
uri,
value
} = fileProps;

Check warning on line 154 in app/lib/file-context/indexer.js

View check run for this annotation

Codecov / codecov/patch

app/lib/file-context/indexer.js#L154

Added line #L154 was not covered by tests

this._emit('file-content-changed', uri);

Check warning on line 156 in app/lib/file-context/indexer.js

View check run for this annotation

Codecov / codecov/patch

app/lib/file-context/indexer.js#L156

Added line #L156 was not covered by tests

return this.add(toFileUrl(uri), value);
return this.add(toFileUrl(uri), value, processor);

Check warning on line 158 in app/lib/file-context/indexer.js

View check run for this annotation

Codecov / codecov/patch

app/lib/file-context/indexer.js#L158

Added line #L158 was not covered by tests
}

/**
Expand Down Expand Up @@ -345,7 +346,8 @@ module.exports = class Indexer {
/**
* @param { {
* uri: string,
* localValue?: string
* localValue?: string,
* processor?: string
* } } item
*
* @return {IndexItem}
Expand All @@ -355,6 +357,7 @@ function createIndexItem(item) {
const {
uri,
localValue,
processor,
...rest
} = item;

Expand All @@ -373,7 +376,8 @@ function createIndexItem(item) {
this.localValue = value;
},
file,
localValue
localValue,
processor
};

}
10 changes: 10 additions & 0 deletions app/lib/file-context/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ module.exports = class Processor {
process(item) {
this._logger.info('processor:process', item.uri);

if (item.processor) {
const processor = this._processors.find(processor => processor.id === item.processor);

Check warning on line 42 in app/lib/file-context/processor.js

View check run for this annotation

Codecov / codecov/patch

app/lib/file-context/processor.js#L42

Added line #L42 was not covered by tests

if (processor) {
return processor.process(item);

Check warning on line 45 in app/lib/file-context/processor.js

View check run for this annotation

Codecov / codecov/patch

app/lib/file-context/processor.js#L44-L45

Added lines #L44 - L45 were not covered by tests
}

this._logger.warn('processor:process', `Processor with id ${ item.processor } not found`);

Check warning on line 48 in app/lib/file-context/processor.js

View check run for this annotation

Codecov / codecov/patch

app/lib/file-context/processor.js#L48

Added line #L48 was not covered by tests
}

const processor = this._processors.find(processor => processor.extensions.includes(getFileExtension(item.file.path)));

if (!processor) {
Expand Down
3 changes: 2 additions & 1 deletion app/lib/file-context/processors/bpmnProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const {
} = require('./util');

module.exports = {
extensions: [ '.bpmn', '.xml' ],
id: 'bpmn',
extensions: [ '.bpmn' ],
process: async (item) => {
let rootElement, ids, linkedIds;

Expand Down
1 change: 1 addition & 0 deletions app/lib/file-context/processors/dmnProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const {
} = require('./util');

module.exports = {
id: 'dmn',
extensions: [ '.dmn' ],
process: async (item) => {
let rootElement, ids;
Expand Down
1 change: 1 addition & 0 deletions app/lib/file-context/processors/formProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
const assert = require('node:assert');

module.exports = {
id: 'form',
extensions: [ '.form' ],
process: async (item) => {
let formId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

module.exports = {
id: 'processApplication',
extensions: [ '.process-application' ],
process: async (item) => {
return {
Expand Down
1 change: 1 addition & 0 deletions app/lib/file-context/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type IndexItem = {
file: File,
localValue?: any,
metadata: Metadata,
processor?: string,
uri: string,
value: any,
[key: string]: any
Expand Down
49 changes: 33 additions & 16 deletions app/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,45 +224,62 @@ renderer.on('system-clipboard:write-text', function(options, done) {
});

// file context //////////
renderer.on('file-context:add-root', function(filePath, done) {
renderer.on('file-context:add-root', function(options, done) {
const { filePath } = options;

fileContext.addRoot(filePath);

done(null);
});

renderer.on('file-context:remove-root', function(filePath, done) {
renderer.on('file-context:remove-root', function(options, done) {
const { filePath } = options;

fileContext.removeRoot(filePath);

done(null);
});

renderer.on('file-context:file-opened', function(filePath, value, done) {
fileContext.fileOpened({ uri: toFileUrl(filePath), value });

done(null);
});
renderer.on('file-context:file-opened', function(options, done) {
const {
filePath,
processor,
value
} = options;

renderer.on('file-context:file-content-changed', function(filePath, value, done) {
fileContext.fileContentChanged({ uri: toFileUrl(filePath), value });
fileContext.fileOpened({
processor,
uri: toFileUrl(filePath),
value
});

done(null);
});

renderer.on('file-context:file-closed', function(filePath, done) {
fileContext.fileClosed(toFileUrl(filePath));

done(null);
});
renderer.on('file-context:file-content-changed', function(options, done) {
const {
filePath,
processor,
value
} = options;

renderer.on('file:content-changed', function(filePath, contents, done) {
fileContext.fileContentChanged({
processor,
uri: toFileUrl(filePath),
value: contents
value
});

done(null);
});

renderer.on('file-context:file-closed', function(options, done) {
const { filePath } = options;

fileContext.fileClosed(toFileUrl(filePath));

done(null);
});

// filesystem //////////

renderer.on('file:read', function(filePath, options = {}, done) {
Expand Down
42 changes: 39 additions & 3 deletions client/src/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2109,18 +2109,38 @@ export class App extends PureComponent {

_onTabOpened(tab) {
if (!this.isUnsaved(tab)) {
this.getGlobal('backend').send('file-context:file-opened', tab.file.path, undefined);
const {
file,
type
} = tab;

this.getGlobal('backend').send('file-context:file-opened', {
filePath: file.path,
processor: getProcessor(type)
});
}
}

_onTabClosed(tab) {
if (!this.isUnsaved(tab)) {
this.getGlobal('backend').send('file-context:file-closed', tab.file.path);
const { file } = tab;

this.getGlobal('backend').send('file-context:file-closed', {
filePath: file.path,
});
}
}

_onTabSaved(tab) {
this.getGlobal('backend').send('file-context:file-content-changed', tab.file.path, undefined);
const {
file,
type
} = tab;

this.getGlobal('backend').send('file-context:file-content-changed', {
filePath: file.path,
processor: getProcessor(type)
});
}

render() {
Expand Down Expand Up @@ -2537,3 +2557,19 @@ function failSafe(fn, errorHandler) {
}
};
}

function getProcessor(type) {
if (type === 'cloud-bpmn') {
return 'bpmn';
}

if (type === 'cloud-dmn') {
return 'dmn';

Check warning on line 2567 in client/src/app/App.js

View check run for this annotation

Codecov / codecov/patch

client/src/app/App.js#L2567

Added line #L2567 was not covered by tests
}

if (type === 'cloud-form') {
return 'form';

Check warning on line 2571 in client/src/app/App.js

View check run for this annotation

Codecov / codecov/patch

client/src/app/App.js#L2571

Added line #L2571 was not covered by tests
}

return null;
}
Loading

0 comments on commit 5182a0b

Please sign in to comment.