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

[vscode] support (Neo)Vim by coc.nvim #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions coc-mlir/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*
!/out/
*.map
!/prebuilds/
32 changes: 32 additions & 0 deletions coc-mlir/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# MLIR

Ported from [vscode-mlir](https://github.com/llvm/vscode-mlir).

Because some APIs of [vscode](github.com/microsoft/vscode) are missing in
[coc.nvim](https://github.com/neoclide/coc.nvim), disable some features
temporarily:

- command `mlir.viewPDLLOutput`: miss
`vscode.workspace.openTextDocument({language, content})`
- custom editor `mlir.bytecode`: miss
`vscode.window.registerCustomEditorProvider()`
- filesystem `mlir.bytecode-mlir`: miss `vscode.workspace.registerFileSystemProvider()`
- use `chokidar.watch()` to detect the changes of the paths of language
servers: miss `vscode.Disposable.constructor()`

## Install

- [coc-marketplace](https://github.com/fannheyward/coc-marketplace)
- [npm](https://www.npmjs.com/package/coc-mlir)
- vim:

```vim
" command line
CocInstall coc-mlir
" or add the following code to your vimrc
let g:coc_global_extensions = ['coc-mlir', 'other coc-plugins']
```

## Usage

Refer [vscode-mlir](https://github.com/llvm/vscode-mlir).
213 changes: 213 additions & 0 deletions coc-mlir/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
{
"name": "coc-mlir",
"displayName": "MLIR",
"description": "MLIR Language Extension",
"version": "0.0.11",
"publisher": "llvm-vs-code-extensions",
"homepage": "https://mlir.llvm.org/",
"icon": "icon.png",
"engines": {
"coc": "^0.0.82"
},
"categories": [
"Programming Languages"
],
"keywords": [
"coc.nvim",
"LLVM",
"MLIR",
"PDLL",
"TableGen",
"tblgen",
"tablegen"
],
"activationEvents": [
"onFileSystem:mlir.bytecode-mlir",
"onCustomEditor:mlir.bytecode",
"onLanguage:mlir",
"onLanguage:pdll",
"onLanguage:tablegen"
],
"main": "./out/extension.js",
"scripts": {
"patch": "scripts/patch.sh ../src/*.ts",
"prepack": "npm run patch && tsc -p ./",
"compile": "tsc -watch -p ./",
"format": "clang-format -i --glob=\"{src,test}/*.ts\"",
"package": "vsce package",
"git-clang-format": "git-clang-format"
},
"dependencies": {
"base64-js": "^1.5.1",
"chokidar": "3.5.2"
},
"devDependencies": {
"@types/mocha": "^7.0.2",
"@types/node": "^14.17.0",
"clang-format": "^1.8.0",
"coc.nvim": "^0.0.83-next.18",
"typescript": "^4.6.4"
},
"repository": {
"type": "git",
"url": "https://github.com/llvm/vscode-mlir"
},
"contributes": {
"customEditors": [
{
"viewType": "mlir.bytecode",
"displayName": "MLIR Bytecode",
"priority": "default",
"selector": [
{
"filenamePattern": "*.mlirbc"
}
]
}
],
"languages": [
{
"id": "mlir",
"aliases": [
"MLIR",
"mlir"
],
"extensions": [
".mlir",
".mlirbc"
],
"configuration": "./language-configuration.json"
},
{
"id": "mlir-injection"
},
{
"id": "pdll",
"aliases": [
"PDLL",
"pdll"
],
"extensions": [
".pdll"
],
"configuration": "./pdll-language-configuration.json"
},
{
"id": "tablegen",
"aliases": [
"TableGen",
"tblgen"
],
"extensions": [
".td"
],
"configuration": "./tablegen-language-configuration.json"
}
],
"grammars": [
{
"language": "mlir",
"scopeName": "source.mlir",
"path": "./grammar.json"
},
{
"language": "mlir-injection",
"scopeName": "markdown.mlir.codeblock",
"path": "markdown-grammar.json",
"injectTo": [
"text.html.markdown"
],
"embeddedLanguages": {
"meta.embedded.block.mlir": "mlir",
"meta.embedded.block.pdll": "pdll",
"meta.embedded.block.tablegen": "tablegen"
}
},
{
"scopeName": "source.cpp.mlir",
"path": "./cpp-grammar.json",
"injectTo": [
"source.cpp"
],
"embeddedLanguages": {
"source.mlir": "mlir"
}
},
{
"language": "pdll",
"scopeName": "source.pdll",
"path": "./pdll-grammar.json"
},
{
"language": "tablegen",
"scopeName": "source.tablegen",
"path": "./tablegen-grammar.json"
}
],
"configuration": {
"type": "object",
"title": "MLIR",
"properties": {
"mlir.server_path": {
"scope": "resource",
"type": "string",
"description": "The file path of the mlir-lsp-server executable."
},
"mlir.pdll_server_path": {
"scope": "resource",
"type": "string",
"description": "The file path of the mlir-pdll-lsp-server executable."
},
"mlir.pdll_compilation_databases": {
"scope": "resource",
"type": "array",
"description": "A list of `pdll_compile_commands.yml` database files containing information about .pdll files processed by the server."
},
"mlir.tablegen_server_path": {
"scope": "resource",
"type": "string",
"description": "The file path of the tblgen-lsp-server executable."
},
"mlir.tablegen_compilation_databases": {
"scope": "resource",
"type": "array",
"description": "A list of `tablegen_compile_commands.yml` database files containing information about .td files processed by the server."
},
"mlir.onSettingsChanged": {
"type": "string",
"default": "prompt",
"description": "Action taken when a setting change requires a server restart to take effect.",
"enum": [
"prompt",
"restart",
"ignore"
],
"enumDescriptions": [
"Prompt the user for restarting the server",
"Automatically restart the server",
"Do nothing"
]
}
}
},
"commands": [
{
"command": "mlir.restart",
"title": "mlir: Restart language server"
},
{
"command": "mlir.viewPDLLOutput",
"title": "mlir-pdll: View PDLL output"
}
],
"menus": {
"editor/context": [
{
"command": "mlir.viewPDLLOutput",
"group": "z_commands",
"when": "editorLangId == pdll"
}
]
}
}
}
2 changes: 2 additions & 0 deletions coc-mlir/scripts/patch.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env -S perl -p
s=//#==;
7 changes: 7 additions & 0 deletions coc-mlir/scripts/patch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -e
cd "$(dirname "$(dirname "$(readlink -f "$0")")")"

for file; do
scripts/patch.pl "$file" | cpp -DHAVE_COC_NVIM -xassembler-with-cpp -nostdinc -P -C -o"${file#*/}"
done
3 changes: 3 additions & 0 deletions coc-mlir/src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# all ts files are generated by `npm run patch`
*
!.gitignore
11 changes: 11 additions & 0 deletions coc-mlir/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../tsconfig",
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"outDir": "out",
"rootDir": "src"
},
"include": [
"src"
],
}
2 changes: 2 additions & 0 deletions src/command.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//# #if HAVE_VSCODE
import * as vscode from 'vscode';
import {MLIRContext} from './mlirContext';

Expand All @@ -23,3 +24,4 @@ export abstract class Command extends vscode.Disposable {
*/
abstract execute(...args: any[]): any;
}
//# #endif
4 changes: 4 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
//# #if HAVE_VSCODE
import * as vscode from 'vscode';
//# #elif HAVE_COC_NVIM
//# import * as vscode from 'coc.nvim';
//# #endif

/**
* Gets the config value `mlir.<key>`, with an optional workspace folder.
Expand Down
6 changes: 6 additions & 0 deletions src/configWatcher.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import * as chokidar from 'chokidar';
//# #if HAVE_VSCODE
import * as vscode from 'vscode';
//# #elif HAVE_COC_NVIM
//# import * as vscode from 'coc.nvim';
//# #endif

import * as config from './config';
import {MLIRContext} from './mlirContext';
Expand Down Expand Up @@ -71,6 +75,7 @@ export async function activate(
}

// If the server path actually exists, track it in case it changes.
//# #if HAVE_VSCODE
const fileWatcher = chokidar.watch(serverPath, fileWatcherConfig);
fileWatcher.on('all', (event, _filename, _details) => {
if (event != 'unlink') {
Expand All @@ -81,5 +86,6 @@ export async function activate(
});
mlirContext.subscriptions.push(
new vscode.Disposable(() => { fileWatcher.close(); }));
//# #endif
}
}
11 changes: 9 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
//# #if HAVE_VSCODE
import * as vscode from 'vscode';

import {registerMLIRExtensions} from './MLIR/mlir';
import {MLIRContext} from './mlirContext';
// https://github.com/neoclide/coc.nvim/discussions/4918
import {registerPDLLExtensions} from './PDLL/pdll';
//# #elif HAVE_COC_NVIM
//# import * as vscode from 'coc.nvim';
//# #endif

import {MLIRContext} from './mlirContext';

/**
* This method is called when the extension is activated. The extension is
Expand All @@ -22,8 +27,10 @@ export function activate(context: vscode.ExtensionContext) {
mlirContext.dispose();
await mlirContext.activate(outputChannel);
}));
//# #if HAVE_VSCODE
registerMLIRExtensions(context, mlirContext);
registerPDLLExtensions(context, mlirContext);
//# #endif

mlirContext.activate(outputChannel);
}
Loading