Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Link Definition and Disambiguation #122

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions docs/proposal-link-definition-and-disambiguation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Proposal: Link Definition and Disambiguation

## Current status

- We generate link ref defs from wiki-links inline
- Wiki links are expected to be the full source of truth, but we don't have enough information to conclusively disambiguate between files
- that have the same file name (in different directories)
- that have the same title (if autocompletion is by title)

## Solution

- Don't wipe out link ref defs. Only add/remove as needed. This can be our metadata for disambiguation.

Let's say we have two documents in the workspace with the same title "Some Title"

- We would have autocompletion base on title of the document
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could autocomplete always be done with a combination of title and file path within the workspace - in a style of "My title - foo/bar/my-title.md"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Added this now.

- Each autocompletion entry could be in format:
**Document title** - *path/to/document.md*
- This generates a link (typically a title, but could also have e.g. `:2` to disambiguate multiple links in the same file)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I would prefer the local links to use style [[foo/bar/my-title]] - would this be configurable?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jojanaho, to clarify, do you mean you prefer foo/bar/my-title for just the disambiguated links in case of title conflicts, or always?

It could be configurable, since it's an arbitrary label. Options could include:

  • file-name.md
  • Title Cased File Name
  • Document Title
  • Arbitrary Label you write yourself

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always, since in my case it would improve readability - e.g [[book-summaries/war-and-peace]]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And to be exact, we have the freedom for arbitrary labels only when link ref defs are in use :)

- The label doesn't matter, it could be used as a display label. We'll just auto-generate something sensible. Could even be a user setting.
- They would look like this:
```
[[Some File]]
[[Some File:2]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so to disambiguate between the two or more title-cased wikilinks within a document. I think this solution would be okay if user wants to use title-cased wikilinks, which would lock them into link ref defs. Again personally I'd still like to use file paths to disambiguate - in many cases it could also be more readable (e.g. [[active/master-plan]] - [[obsolete/master-plan]] vs [[Master Plan]] - [[Master Plan:2]]

```
- The link ref definitions become equivalent to import statements in a programming language, telling us where we are importing and what:
`[Some File]: some-file.md: "Some file in root directory"`
`[Some File:2]: subdirectory/some-file.md: "Some file in a subdirectory"`
- Here the title component of the link ref definition becomes optional since display name can be controlled by the label inside link.
- Note that we are adding .md here by default, but can omit that based on user preference as per @jojanaho's proposal
- Fixes GitHub UI rendering
- Breaks GitHub Pages links, but we'll override links in JavaScript as we do titles right now
- Going forward, Gatsby or other build tool can consume these directly
- This will also help us with anchor links, because we don't need to put them inline in the label anymore:
- `[Some File With Anchor Section]: some-file.md#anchor`
- This would also allow us to be more permissive of file names
- Markdown labels, the target needs to be a valid URI so we may needs to URI encode
- `[Some File With Anchor Section]: Some%20File%20With%20Anchor%20Section.md`
- For migrating into this structure, we'll need to do a bit of guesswork and/or manual editing, but we can build tooling to make this easier (e.g. in `foam-cli janitor/migrate`) and ensure lint consistency with `foam-cli lint`
- In VS Code we can surface any issues in the Problems/Diagnostic pane
- We could also show syntax errors (red squigglies) inline, with a `Quick Fix...` menu
- This all means that we will have to severely change Markdown Notes or replace it
- Take into account @digiguru's work on supporting accents etc.

## Plan

- CLI team is finishing first iteration of foam-cli janitor/migrate/lint
- This will not affect their work, and we'll ensure their work can be used in the new structure
- Link ref def parsing is already on their branch, let's try to land that ASAP
- Fix the .md generation @riccardo
- Change the way the links are generated in vs code
- Add a bit of javascript
- Start treating metadata as source of truth
- Definitions are already on https://github.com/foambubble/foam/pull/112/files
- For autocompletion, @jevakallio has started a spike, aim to get something prototyped by Friday