Code Link

by observerw
5
4
3
2
1
Score: 42/100

Description

Category: Coding & Technical Tools

The Code Link plugin allows you to link directly to code files and even specific symbols within those files, such as functions or classes, making it ideal for referencing code in your Obsidian notes. By embedding or previewing the contents of linked code, you can focus on the specific parts of a project that interest you. The plugin supports hover previews and embedded previews of code files. Additionally, tag search allows you to filter through code by symbols, making it easier to navigate complex codebases. With support for multiple languages and integration with TreeSitter, the plugin enhances code documentation and study in Obsidian.

Reviews

No reviews yet.

Stats

25
stars
822
downloads
1
forks
669
days
127
days
559
days
7
total PRs
1
open PRs
0
closed PRs
6
merged PRs
2
total issues
1
open issues
1
closed issues
18
commits

Latest Version

2 years ago

Changelog

README file from

Github

GitHub stars latest download Github release GitHub release (latest by date including pre-releases)

[ English | 简体中文 ]

Display code in Obsidian, and only the part you're interested in!

main

  • Link to code files as you would link to notes, and you can preview their contents.
  • Even better, through symbol search/tag search/code outline (or whatever you want to call it.), you can link directly to a specific symbol in the code file (such as a class, a function, or a method within a class).

By creating links with symbols, you can reference only the code parts that interest you in your notes and avoid distractions from other content. This is particularly useful when taking code notes (for example, when studying a complex open-source project).

⚠️ATTENTION

  • To be able to link to the code file with internal link, make sure that the Settings - Files and Links - Detect all types of files option are enabled.
  • Embed preview only works in reading view, so if you find that the preview is not displayed, please switch to reading view by pressing Ctrl/Cmd + E.
  • Before you perform a tag search, make sure that Settings - Code Link - Enable tag search option is enabled.

Usage

  1. Create a folder in your obsidian repository for storing imported projects of your code projects, the default path is projects.
  2. Open Command Palette and run Code Link: Import project, select the project folder you want to import (see this section below), then the project will be imported into the folder you created in step 1.
  3. Open editor, link to the code file just like linking to a note, then you can preview the code in the editor.

Code Preview

Supports both hover preview and embed preview of the code file.

Below the embed preview lists the link to the referenced code file, and the tag path to the current symbol (e.g., if you link to a method named methodB in a class named ClassA, the tag path is class ClassA > def methodB). When you click on a symbol in the tag path, the embed preview will temporarily switch the content of the displayed code to the content of that symbol.

Place the cursor behind the code link (e.g. [[main.py]]|, where | is the cursor) will trigger tag search. The code link will be replaced when the specified symbol is selected in the tag search. Entering something from this position will filter the entries in the tag search, e.g. [[main.py]]def will filter all entries in the entry that contain the def keyword. Note that the entry needs to be immediately followed by ]].

⚠️ATTENTION: After installing the plugin, if the tag search fails to trigger, try closing and reopening Obsidian.

This feature is implemented with the help of TreeSitter and .scm files from the zed editor. Current support languages are: C, C++, JavaScript, TypeScript, Rust, Go, Python. If you want more languages to be supported, please consider writing tree-sitter queries for other languages modeled after existing .scm files and open a pull request. I would appreciate that!

Import Project Into Obsidian Vault

Obsidian only allows to link to files within the vault, so you need to import the project into your vault before you can link to it.

To import a project, open command palette and run Code Link: Import project, then select the project folder you want to import. The project will be imported into the projects folder.

Note that "import" means create symbol links (or file shortcuts in Windows) to the original files. Symlink are just reference to the original file, so if you delete the original file, the symlink will be broken.