Skip to content

Commit

Permalink
Process review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pderaaij committed Oct 11, 2024
1 parent ce662af commit 87807e9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
14 changes: 13 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 10 additions & 15 deletions packages/foam-vscode/src/core/model/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Emitter } from '../common/event';
import { ResourceProvider } from './provider';
import { IDisposable } from '../common/lifecycle';
import { IDataStore } from '../services/datastore';
import { TrieMap } from 'mnemonist';
import TrieMap from 'mnemonist/trie-map';

export class FoamWorkspace implements IDisposable {
private onDidAddEmitter = new Emitter<Resource>();
Expand Down Expand Up @@ -34,10 +34,9 @@ export class FoamWorkspace implements IDisposable {

set(resource: Resource) {
const old = this.find(resource.uri);
const normalizedPath = normalize(resource.uri.path);

// store resource
this._resources.set(this.getReversedIdentifier(normalizedPath), resource);
this._resources.set(this.getTrieIdentifier(resource.uri.path), resource);

isSome(old)
? this.onDidUpdateEmitter.fire({ old: old, new: resource })
Expand All @@ -46,8 +45,8 @@ export class FoamWorkspace implements IDisposable {
}

delete(uri: URI) {
const deleted = this._resources.get(this.getReversedIdentifier(uri));
this._resources.delete(this.getReversedIdentifier(uri));
const deleted = this._resources.get(this.getTrieIdentifier(uri));
this._resources.delete(this.getTrieIdentifier(uri));

isSome(deleted) && this.onDidDeleteEmitter.fire(deleted);
return deleted ?? null;
Expand Down Expand Up @@ -79,19 +78,17 @@ export class FoamWorkspace implements IDisposable {
}

public listByIdentifier(identifier: string): Resource[] {
let needle = this.getReversedIdentifier(identifier);
let needle = this.getTrieIdentifier(identifier);

const mdNeedle =
getExtension(normalize(identifier)) !== this.defaultExtension
? this.getReversedIdentifier(identifier + this.defaultExtension)
? this.getTrieIdentifier(identifier + this.defaultExtension)
: undefined;

const resources: Resource[] = [];

this._resources.find(needle).forEach(elm => {
if (elm[0].indexOf(getExtension(normalize(identifier))) > 0) {
resources.push(elm[1]);
}
resources.push(elm[1]);
});
if (mdNeedle) {
this._resources.find(mdNeedle).forEach(elm => resources.push(elm[1]));
Expand Down Expand Up @@ -141,7 +138,7 @@ export class FoamWorkspace implements IDisposable {
*
* @param reference the URI path to reverse
*/
private getReversedIdentifier(reference: URI | string): string {
private getTrieIdentifier(reference: URI | string): string {
let path: string;
if (reference instanceof URI) {
path = (reference as URI).path;
Expand All @@ -160,7 +157,7 @@ export class FoamWorkspace implements IDisposable {

public find(reference: URI | string, baseUri?: URI): Resource | null {
if (reference instanceof URI) {
return this._resources.get(this.getReversedIdentifier(reference)) ?? null;
return this._resources.get(this.getTrieIdentifier(reference)) ?? null;
}
let resource: Resource | null = null;
const [path, fragment] = (reference as string).split('#');
Expand All @@ -174,9 +171,7 @@ export class FoamWorkspace implements IDisposable {
: isSome(baseUri)
? baseUri.resolve(candidate).path
: null;
resource = this._resources.get(
normalize(searchKey).split('/').reverse().join('/')
);
resource = this._resources.get(this.getTrieIdentifier(searchKey));
if (resource) {
break;
}
Expand Down
7 changes: 4 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5422,7 +5422,7 @@ flatted@^3.1.0:
integrity sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==

"foam-vscode@file:/Users/paulderaaij/projects/foam/packages/foam-vscode":
version "0.25.12"
version "0.26.0"
resolved "file:packages/foam-vscode"
dependencies:
dateformat "4.5.1"
Expand All @@ -5432,6 +5432,7 @@ flatted@^3.1.0:
lodash "^4.17.21"
lru-cache "^7.14.1"
markdown-it-regex "^0.2.0"
mnemonist "^0.39.8"
remark-frontmatter "^2.0.0"
remark-parse "^8.0.2"
remark-wiki-link "^0.0.4"
Expand Down Expand Up @@ -7441,7 +7442,7 @@ js-sdsl@^4.1.4:

js-sha1@^0.7.0:
version "0.7.0"
resolved "https://registry.yarnpkg.com/js-sha1/-/js-sha1-0.7.0.tgz#fecaf5f36bb09a51b01da46b43a207c8452c9c1e"
resolved "https://registry.npmjs.org/js-sha1/-/js-sha1-0.7.0.tgz"
integrity sha512-oQZ1Mo7440BfLSv9TX87VNEyU52pXPVG19F9PL3gTgNt0tVxlZ8F4O6yze3CLuLx28TxotxvlyepCNaaV0ZjMw==

"js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0:
Expand Down Expand Up @@ -8845,7 +8846,7 @@ pascal-case@^3.1.2:

path-browserify@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-1.0.1.tgz#d98454a9c3753d5790860f16f68867b9e46be1fd"
resolved "https://registry.npmjs.org/path-browserify/-/path-browserify-1.0.1.tgz"
integrity sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==

path-exists@^3.0.0:
Expand Down

0 comments on commit 87807e9

Please sign in to comment.