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
4 changes: 4 additions & 0 deletions coc-graphviz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.tgz
out
node_modules
yarn.lock
5 changes: 5 additions & 0 deletions coc-graphviz/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*
!/README.md
!/package.json
!/out/
*.map
29 changes: 29 additions & 0 deletions coc-graphviz/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Graphviz Support

Ported from [vscode-graphviz](https://github.com/joaompinto/vscode-graphviz).

![graphvizPreview](https://github.com/user-attachments/assets/d3dac671-fa7d-46f2-9367-d28fa60c637c)

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 `graphviz.previewToSide`: miss `vscode.ViewColumn`
- save as svg: miss `vscode.window.showSaveDiaglog()`

## Install

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

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

## Usage

Refer [vscode-graphviz](https://github.com/joaompinto/vscode-graphviz).
168 changes: 168 additions & 0 deletions coc-graphviz/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
{
"name": "coc-graphviz",
"displayName": "Graphviz (dot) language support for Visual Studio Code",
"description": "This extension provides GraphViz (dot) language support for Visual Studio Code",
"version": "0.0.9",
"publisher": "joaompinto",
"author": "João Pinto <lamego.pinto@gmail.com>",
"keywords": [
"coc.nvim"
],
"contributors": [
"Jan Dolejsi"
],
"license": "MIT",
"readme": "README.md",
"repository": {
"type": "git",
"url": "https://github.com/joaompinto/vscode-graphviz"
},
"galleryBanner": {
"color": "#69c",
"theme": "light"
},
"bugs": "https://github.com/joaompinto/vscode-graphviz/issues",
"homepage": "https://github.com/joaompinto/vscode-graphviz/blob/master/README.md",
"icon": "images/icon.png",
"main": "./out/src/extension.js",
"engines": {
"coc": "^0.0.82"
},
"categories": [
"Programming Languages",
"Snippets"
],
"activationEvents": [
"onLanguage:dot",
"onCommand:graphviz.preview"
],
"contributes": {
"languages": [
{
"id": "dot",
"aliases": [
"Graphviz (DOT)"
],
"extensions": [
".gv",
".dot",
".DOT"
],
"configuration": "dot/dot.configuration.json"
}
],
"grammars": [
{
"language": "dot",
"scopeName": "source.dot",
"path": "dot/syntaxes/dot.tmLanguage"
}
],
"snippets": [
{
"language": "dot",
"path": "dot/snippets/snippets/dot.json"
}
],
"configuration": {
"type": "object",
"title": "Graphviz Configuration",
"properties": {
"Graphviz.runInterval": {
"type": "number",
"default": 1000,
"description": "Control how often we will be checking for file changes"
}
}
},
"keybindings": [
{
"command": "graphviz.preview",
"key": "ctrl+shift+v",
"mac": "shift+cmd+v",
"when": "editorTextFocus && editorLangId == dot"
},
{
"command": "graphviz.previewToSide",
"key": "ctrl+k v",
"mac": "cmd+k shift+v",
"when": "editorTextFocus && editorLangId == dot"
}
],
"commands": [
{
"command": "graphviz.preview",
"title": "Toggle Preview",
"category": "Graphviz"
},
{
"command": "graphviz.previewToSide",
"title": "Open Preview to the Side",
"category": "Graphviz",
"icon": {
"light": "images/light/open-preview.svg",
"dark": "images/dark/open-preview.svg"
}
}
],
"menus": {
"editor/title": [
{
"command": "graphviz.previewToSide",
"when": "resourceLangId == dot",
"group": "navigation"
}
],
"editor/context": [
{
"command": "graphviz.previewToSide",
"when": "resourceLangId == dot"
}
],
"editor/title/context": [
{
"command": "graphviz.previewToSide",
"when": "resourceLangId == dot"
}
],
"explorer/context": [
{
"command": "graphviz.preview",
"when": "resourceLangId == dot"
}
],
"commandPalette": [
{
"command": "graphviz.preview",
"when": "resourceLangId == dot"
},
{
"command": "graphviz.previewToSide",
"when": "resourceLangId == dot"
}
]
}
},
"scripts": {
"patch": "scripts/patch.sh ../src/*.ts",
"watch": "tsc -watch -p ./",
"prepack": "npm run patch && tsc -p ./"
},
"devDependencies": {
"@types/mocha": "^8.2.1",
"@types/node": "^18.0.0",
"@types/tmp": "^0.2.0",
"coc-helper": "^0.16.3",
"coc-webview": "^0.12.0",
"coc.nvim": "^0.0.83-next.18",
"mocha": "^10.2.0",
"socket.io": "^4.7.4",
"typescript": "^4.2.3"
},
"dependencies": {
"@hpcc-js/wasm": "^1.3.0",
"dot-language-server": "1.2.0",
"open": "^8.0.2",
"tmp": "^0.2.1"
}
}
2 changes: 2 additions & 0 deletions coc-graphviz/scripts/patch.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env -S perl -p
s=//#==;
8 changes: 8 additions & 0 deletions coc-graphviz/scripts/patch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -e
cd "$(dirname "$(dirname "$(readlink -f "$0")")")"

for file; do
# https://stackoverflow.com/questions/30167851/how-to-suppress-a-missing-termination-character-warning-in-cpp/30174912#30174912
scripts/patch.pl "$file" | cpp -DHAVE_COC_NVIM -xassembler-with-cpp -nostdinc -P -C -o"${file#*/}"
done
4 changes: 4 additions & 0 deletions coc-graphviz/src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# all ts files are generated by `npm run patch`
*
!.gitignore
!util.ts
18 changes: 18 additions & 0 deletions coc-graphviz/src/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { WebviewAPI } from 'coc-webview'
import { Extension, extensions, window } from 'coc.nvim'

let webviewExt: Extension<WebviewAPI> | undefined

export const getWebviewAPI = () => {
if (!webviewExt) {
webviewExt = extensions.all.find((ext) => ext.id === 'coc-webview') as
| Extension<WebviewAPI>
| undefined
}
if (!webviewExt) {
const prompt = 'Please install the coc-webview extension'
void window.showErrorMessage(prompt)
throw new Error(prompt)
}
return webviewExt.exports
}
8 changes: 8 additions & 0 deletions coc-graphviz/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../tsconfig",
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"outDir": "out",
"rootDir": "."
}
}
20 changes: 19 additions & 1 deletion src/ContentUtils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
import { ExtensionContext, Uri, Webview } from "vscode";
import {
ExtensionContext,
Uri,
//# #if HAVE_VSCODE
Webview
} from "vscode";
//# #elif HAVE_COC_NVIM
//# } from "coc.nvim";
//# import { Webview } from "coc-webview";
//# import { resolve } from "path";
//# #endif
var fs = require("fs");

export const CONTENT_FOLDER = "content";

export async function getPreviewTemplate(context: ExtensionContext, templateName: string): Promise<string> {
//# #if HAVE_VSCODE
let previewPath = Uri.joinPath(context.extensionUri, CONTENT_FOLDER, templateName).fsPath;
//# #elif HAVE_COC_NVIM
//# let previewPath = /* Uri.joinPath */resolve(context.extensionPath/* extensionUri */, CONTENT_FOLDER, templateName)/* .fsPath */;
//# #endif

return (await fs.promises.readFile(previewPath, { encoding: "utf-8", flag: 'r' })).toString();
}
Expand Down Expand Up @@ -39,7 +53,11 @@ function isAbsoluteWebview(attribValue: string): boolean {
}

function getWebviewUri(extensionContext: ExtensionContext, relativePath: string, fileName: string, webview?: Webview): Uri {
//# #if HAVE_VSCODE
return asWebviewUri(Uri.joinPath(extensionContext.extensionUri, relativePath, fileName), webview);
//# #elif HAVE_COC_NVIM
//# return asWebviewUri(/* Uri.joinPath */Uri.parse("file://" + resolve(extensionContext.extensionPath/* extensionUri */, relativePath, fileName)), webview);
//# #endif
}

function asWebviewUri(localUri: Uri, webview?: Webview): Uri {
Expand Down
Loading