@finos/legend-application-pure-ide
Version:
Legend Pure IDE application core
74 lines • 3.14 kB
JavaScript
/**
* Copyright (c) 2020-present, Goldman Sachs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { computed, makeObservable, observable } from 'mobx';
import { SearchResultCoordinate, SearchResultEntry, } from '../server/models/SearchEntry.js';
import { deleteEntry, guaranteeNonNullable } from '@finos/legend-shared';
export class ReferenceUsageResult {
ideStore;
usageConcept;
searchEntries = [];
constructor(ideStore, usageConcept, references, searchResultCoordinates) {
makeObservable(this, {
searchEntries: observable,
numberOfFiles: computed,
numberOfResults: computed,
});
this.ideStore = ideStore;
this.usageConcept = usageConcept;
const fileMap = new Map();
references.forEach((ref, idx) => {
let entry;
if (fileMap.has(ref.source)) {
entry = guaranteeNonNullable(fileMap.get(ref.source));
}
else {
entry = new SearchResultEntry();
entry.sourceId = ref.source;
fileMap.set(ref.source, entry);
}
const coordinates = new SearchResultCoordinate(ref.source, ref.startLine, ref.startColumn, ref.endLine, ref.endColumn);
coordinates.preview = searchResultCoordinates.find((result) => result.sourceId === ref.source &&
result.startLine === ref.startLine &&
result.startColumn === ref.startColumn &&
result.endLine === ref.endLine &&
result.endColumn === ref.endColumn)?.preview;
entry.coordinates.push(coordinates);
});
this.searchEntries = Array.from(fileMap.keys())
.sort((f1, f2) => f1.localeCompare(f2))
.map((file) => {
const entry = guaranteeNonNullable(fileMap.get(file));
// NOTE: sorting the list of coordinates (line has higher precendence than column)
entry.setCoordinates(entry.coordinates
.sort((c1, c2) => c1.startColumn - c2.startColumn)
.sort((c1, c2) => c1.startLine - c2.startLine));
return entry;
});
}
dismissSearchEntry(value) {
deleteEntry(this.searchEntries, value);
if (!this.searchEntries.length) {
this.ideStore.setReferenceUsageResult(undefined);
}
}
get numberOfFiles() {
return this.searchEntries.length;
}
get numberOfResults() {
return this.searchEntries.flatMap((entry) => entry.coordinates).length;
}
}
//# sourceMappingURL=ReferenceUsageResult.js.map