Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion llvm/utils/vscode/llvm/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
node_modules
*~
syntaxes/ll.tmLanguage.json
out/
out/
out
.vscode-test
*.vsix

!.vscode
23 changes: 23 additions & 0 deletions llvm/utils/vscode/llvm/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "extensionHost",
"request": "launch",
"name": "Run Extension",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceRoot}"
],
"autoAttachChildProcesses": true,
"sourceMaps": true,
"outFiles": [
"${workspaceRoot}/out/**/*.js"
],
"preLaunchTask": {
"type": "npm",
"script": "watch"
}
}
]
}
11 changes: 11 additions & 0 deletions llvm/utils/vscode/llvm/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off",
"typescript.preferences.quoteStyle": "single",
}
33 changes: 33 additions & 0 deletions llvm/utils/vscode/llvm/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "compile",
"group": "build",
"presentation": {
"panel": "dedicated",
"reveal": "never"
},
"problemMatcher": [
"$tsc"
]
},
{
"type": "npm",
"script": "watch",
"isBackground": true,
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"panel": "dedicated",
"reveal": "never"
},
"problemMatcher": [
"$tsc-watch"
]
}
]
}
2 changes: 1 addition & 1 deletion llvm/utils/vscode/llvm/.vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
vsc-extension-quickstart.md
syntaxes/ll.tmLanguage.yaml
**/*.ts
**/tsconfig.json
**/tsconfig.json
99 changes: 79 additions & 20 deletions llvm/utils/vscode/llvm/README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,105 @@
# VS Code Extension For LLVM Dev
# LLVM Development VS Code Extension

This VS Code extension provides a comprehensive suite of tools for working with LLVM projects. It includes syntax highlighting, LIT integration, and a custom LLVM IR visualizer with LSP-backed commands.

---

## Features
- LLVM IR files (.ll) syntax highlighting.
(manually translated from `llvm/utils/vim/syntax/llvm.vim`)
- TableGen files (.td) syntax highlighting.
(translated from `llvm/utils/textmate`)
- PatternMatchers for LIT test output.
(`$llvm-lit`, `$llvm-filecheck`)
- Tasks to run LIT on current selected file.
(`Terminal` -> `Run Task` -> `llvm-lit`)

### Syntax Highlighting
- **LLVM IR (.ll)** — syntax highlighting translated from `llvm/utils/vim/syntax/llvm.vim`
- **TableGen (.td)** — syntax highlighting from `llvm/utils/textmate`

### LIT Test Integration
- Pattern matchers for LIT test output (`$llvm-lit`, `$llvm-filecheck`)
- VS Code Tasks to run LIT on the current file:
- `Terminal` → `Run Task` → `llvm-lit`

---

## Installation

```sh
### Prerequisites

```bash
sudo apt-get install nodejs-dev node-gyp npm
sudo npm install -g typescript npx vsce
```

### Install From Source
```sh

```bash
cd <extensions-installation-folder>
cp -r llvm/utils/vscode/llvm .
cd llvm
npm install
npm run vscode:prepublish
```
`<extensions-installation-folder>` is OS dependent.

Please refer to https://code.visualstudio.com/docs/editor/extension-gallery#_where-are-extensions-installed
📌 `<extensions-installation-folder>` is OS dependent. See:
https://code.visualstudio.com/docs/editor/extension-gallery#_where-are-extensions-installed

### Install From Package (.vsix)

First package the extension according to
https://code.visualstudio.com/api/working-with-extensions/publishing-extension#usage.
1. Package the extension:
https://code.visualstudio.com/api/working-with-extensions/publishing-extension#usage
2. Install the `.vsix`:
https://code.visualstudio.com/docs/editor/extension-gallery#_install-from-a-vsix

Then install the package according to
https://code.visualstudio.com/docs/editor/extension-gallery#_install-from-a-vsix.
---

## Setup

Set `cmake.buildDirectory` to your build directory.
Set the following in your VS Code settings:

```json
"cmake.buildDirectory": "<your-cmake-build-dir>",
"llvm.server_path": "<path-to-llvm-lsp-server>"
```

If `"llvm.server_path"` is not set, the extension will search for `llvm-lsp-server` in your system `PATH`.

Resources:
- [VS Code User Settings](https://code.visualstudio.com/docs/getstarted/settings)
- [CMake Tools: buildDirectory](https://vector-of-bool.github.io/docs/vscode-cmake-tools/settings.html#cmake-builddirectory)

---

## Development

### Build & Debug

```bash
npm install
npm run compile
```

Alternatively:
1. Open `package.json` in VS Code.
2. Click the `Debug` button next to any script under the `scripts` section.
3. Open `src/extension.ts`, press `F5` (Debug: Start Debugging).
4. A new window titled `[Extension Development Host]` will launch.

### Debugging LSP Communication

In the Extension Development Host:
- Open the **Output** pane (`Ctrl+Shift+U`)
- Select `llvm-lsp-server` from the dropdown
- Make sure the setting `llvm.trace.server` is set to `"messages"` or `"verbose"`

---

## Project Structure

https://code.visualstudio.com/docs/getstarted/settings
### `package.json`
Metadata and configuration:
- Extension name, version, engines, activation events, etc.
- Contributions:
- `languages`, `commands`, `menus`, `configuration`

https://vector-of-bool.github.io/docs/vscode-cmake-tools/settings.html#cmake-builddirectory
### `src/` — TypeScript sources
- `extension.ts`
- Entry point: creates `OutputChannel`, `LLVMContext`, and registers commands
- `llvmContext.ts`
- `WorkspaceFolderContext`: manages `LanguageClient` per workspace
- `LLVMContext`: manages lifecycle, subscriptions, and per-folder context
Loading