@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://json.schemastore.org/prettierrc",
|
||||||
|
"semi": false,
|
||||||
|
"tabWidth": 4,
|
||||||
|
"singleQuote": false,
|
||||||
|
"printWidth": 100,
|
||||||
|
"trailingComma": "none"
|
||||||
|
}
|
||||||
@@ -1,36 +1,78 @@
|
|||||||
import * as vscode from "vscode";
|
import * as vscode from "vscode"
|
||||||
|
|
||||||
export function formatCdlFile(content: string): string {
|
export function formatCdlFile(content: string): string {
|
||||||
let indentLevel = 0;
|
let indentLevel = 0
|
||||||
const formattedLines = [];
|
const formattedLines = []
|
||||||
for (const line of content.split("\n")) {
|
for (const line of content.split("\n")) {
|
||||||
const strippedLine = line.trim();
|
const strippedLine = line.trim()
|
||||||
if (strippedLine.endsWith("}")) {
|
if (strippedLine.endsWith("}")) {
|
||||||
indentLevel = Math.max(indentLevel - 1, 0);
|
indentLevel = Math.max(indentLevel - 1, 0)
|
||||||
}
|
}
|
||||||
formattedLines.push(" ".repeat(indentLevel) + strippedLine);
|
formattedLines.push(" ".repeat(indentLevel) + strippedLine)
|
||||||
if (strippedLine.endsWith("{")) {
|
if (strippedLine.endsWith("{")) {
|
||||||
indentLevel += 1;
|
indentLevel += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return formattedLines.join("\n");
|
return formattedLines.join("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
export function completionHandler(
|
export function completionHandler(document: vscode.TextDocument, position: vscode.Position) {
|
||||||
document: vscode.TextDocument,
|
const linePrefix = document.lineAt(position).text.substring(0, position.character)
|
||||||
position: vscode.Position
|
const categories = ["MILL", "LATHE", "DRILL"]
|
||||||
) {
|
|
||||||
const linePrefix = document
|
|
||||||
.lineAt(position)
|
|
||||||
.text.substr(0, position.character);
|
|
||||||
if (!linePrefix.endsWith("TYPE ")) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (linePrefix.endsWith("TYPE ")) {
|
||||||
return [
|
return [
|
||||||
new vscode.CompletionItem("o", vscode.CompletionItemKind.Keyword),
|
new vscode.CompletionItem("o", vscode.CompletionItemKind.TypeParameter),
|
||||||
new vscode.CompletionItem("b", vscode.CompletionItemKind.Keyword),
|
new vscode.CompletionItem("b", vscode.CompletionItemKind.TypeParameter),
|
||||||
new vscode.CompletionItem("i", vscode.CompletionItemKind.Keyword),
|
new vscode.CompletionItem("i", vscode.CompletionItemKind.TypeParameter),
|
||||||
new vscode.CompletionItem("d", vscode.CompletionItemKind.Keyword),
|
new vscode.CompletionItem("d", vscode.CompletionItemKind.TypeParameter),
|
||||||
];
|
new vscode.CompletionItem("g", vscode.CompletionItemKind.TypeParameter),
|
||||||
|
new vscode.CompletionItem("s", vscode.CompletionItemKind.TypeParameter)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
if (linePrefix.endsWith("CATEGORY ")) {
|
||||||
|
return categories.map(
|
||||||
|
(cat) => new vscode.CompletionItem(cat, vscode.CompletionItemKind.TypeParameter)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const categoryPrefix = linePrefix.match(/CATEGORY (.*) /)
|
||||||
|
if (categoryPrefix) {
|
||||||
|
const usedCategories = categoryPrefix[1].split(" ")
|
||||||
|
const remainingCategories = categories.filter((cat) => !usedCategories.includes(cat))
|
||||||
|
return remainingCategories.map(
|
||||||
|
(cat) => new vscode.CompletionItem(cat, vscode.CompletionItemKind.TypeParameter)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
export function hoverHandler(document: vscode.TextDocument, position: vscode.Position) {
|
||||||
|
const wordRange = document.getWordRangeAtPosition(position)
|
||||||
|
const word = document.getText(wordRange)
|
||||||
|
const text = document.getText()
|
||||||
|
const lines = text.split("\n")
|
||||||
|
|
||||||
|
let hoverText: string | undefined
|
||||||
|
|
||||||
|
for (const line of lines) {
|
||||||
|
const words = line.split(/\s+/)
|
||||||
|
const wordIndex = words.indexOf(word)
|
||||||
|
|
||||||
|
if (wordIndex > 0) {
|
||||||
|
if (words[wordIndex - 1] === "EVENT") {
|
||||||
|
hoverText = `MOM_${word}`
|
||||||
|
} else if (words[wordIndex - 1] === "PARAM") {
|
||||||
|
hoverText = `mom_${word}`
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hoverText) {
|
||||||
|
return new vscode.Hover(hoverText)
|
||||||
|
}
|
||||||
|
return undefined
|
||||||
}
|
}
|
||||||
|
|||||||
+29
-17
@@ -1,25 +1,23 @@
|
|||||||
import * as vscode from "vscode";
|
import * as vscode from "vscode"
|
||||||
import { formatCdlFile, completionHandler } from "./common/handlers";
|
import { formatCdlFile, completionHandler, hoverHandler } from "./common/handlers"
|
||||||
|
|
||||||
export function activate(context: vscode.ExtensionContext) {
|
export function activate(context: vscode.ExtensionContext) {
|
||||||
const disposable = vscode.languages.registerDocumentFormattingEditProvider(
|
const formatProvider = vscode.languages.registerDocumentFormattingEditProvider(
|
||||||
{ scheme: "file", language: "cdl" },
|
{ scheme: "file", language: "cdl" },
|
||||||
{
|
{
|
||||||
provideDocumentFormattingEdits(
|
provideDocumentFormattingEdits(document: vscode.TextDocument): vscode.TextEdit[] {
|
||||||
document: vscode.TextDocument
|
const text = document.getText()
|
||||||
): vscode.TextEdit[] {
|
const formattedText = formatCdlFile(text)
|
||||||
const text = document.getText();
|
|
||||||
const formattedText = formatCdlFile(text);
|
|
||||||
const fullRange = new vscode.Range(
|
const fullRange = new vscode.Range(
|
||||||
document.positionAt(0),
|
document.positionAt(0),
|
||||||
document.positionAt(text.length)
|
document.positionAt(text.length)
|
||||||
);
|
)
|
||||||
return [vscode.TextEdit.replace(fullRange, formattedText)];
|
return [vscode.TextEdit.replace(fullRange, formattedText)]
|
||||||
},
|
|
||||||
}
|
}
|
||||||
);
|
}
|
||||||
|
)
|
||||||
|
|
||||||
context.subscriptions.push(disposable);
|
context.subscriptions.push(formatProvider)
|
||||||
|
|
||||||
const completionProvider = vscode.languages.registerCompletionItemProvider(
|
const completionProvider = vscode.languages.registerCompletionItemProvider(
|
||||||
{ scheme: "file", language: "cdl" },
|
{ scheme: "file", language: "cdl" },
|
||||||
@@ -30,12 +28,26 @@ export function activate(context: vscode.ExtensionContext) {
|
|||||||
token: vscode.CancellationToken,
|
token: vscode.CancellationToken,
|
||||||
context: vscode.CompletionContext
|
context: vscode.CompletionContext
|
||||||
) {
|
) {
|
||||||
return completionHandler(document, position);
|
return completionHandler(document, position)
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
" " // Trigger completion on space
|
" " // Trigger completion on space
|
||||||
);
|
)
|
||||||
context.subscriptions.push(completionProvider);
|
context.subscriptions.push(completionProvider)
|
||||||
|
|
||||||
|
const hoverProvider = vscode.languages.registerHoverProvider(
|
||||||
|
{ scheme: "file", language: "cdl" },
|
||||||
|
{
|
||||||
|
provideHover(
|
||||||
|
document: vscode.TextDocument,
|
||||||
|
position: vscode.Position,
|
||||||
|
token: vscode.CancellationToken
|
||||||
|
) {
|
||||||
|
return hoverHandler(document, position)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
context.subscriptions.push(hoverProvider)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deactivate() {}
|
export function deactivate() {}
|
||||||
|
|||||||
Generated
+21
-4
@@ -1,15 +1,16 @@
|
|||||||
{
|
{
|
||||||
"name": "cdl",
|
"name": "vscode-cdl-support",
|
||||||
"version": "0.0.1",
|
"version": "0.1.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "cdl",
|
"name": "vscode-cdl-support",
|
||||||
"version": "0.0.1",
|
"version": "0.1.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/vscode": "^1.96.0",
|
"@types/vscode": "^1.96.0",
|
||||||
"@vscode/vsce": "^3.2.1",
|
"@vscode/vsce": "^3.2.1",
|
||||||
|
"prettier": "^3.4.2",
|
||||||
"typescript": "^5.7.2",
|
"typescript": "^5.7.2",
|
||||||
"vite": "^6.0.7"
|
"vite": "^6.0.7"
|
||||||
},
|
},
|
||||||
@@ -2766,6 +2767,22 @@
|
|||||||
"node": ">=10"
|
"node": ">=10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/prettier": {
|
||||||
|
"version": "3.4.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.4.2.tgz",
|
||||||
|
"integrity": "sha512-e9MewbtFo+Fevyuxn/4rrcDAaq0IYxPGLvObpQjiZBMAzB9IGmzlnG9RZy3FFas+eBMu2vA0CszMeduow5dIuQ==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"bin": {
|
||||||
|
"prettier": "bin/prettier.cjs"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=14"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/prettier/prettier?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/pump": {
|
"node_modules/pump": {
|
||||||
"version": "3.0.2",
|
"version": "3.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.2.tgz",
|
||||||
|
|||||||
+2
-1
@@ -2,7 +2,7 @@
|
|||||||
"name": "vscode-cdl-support",
|
"name": "vscode-cdl-support",
|
||||||
"displayName": "vscode-cdl-support",
|
"displayName": "vscode-cdl-support",
|
||||||
"description": "",
|
"description": "",
|
||||||
"version": "0.0.5",
|
"version": "0.1.0",
|
||||||
"publisher": "Christoph",
|
"publisher": "Christoph",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -50,6 +50,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/vscode": "^1.96.0",
|
"@types/vscode": "^1.96.0",
|
||||||
"@vscode/vsce": "^3.2.1",
|
"@vscode/vsce": "^3.2.1",
|
||||||
|
"prettier": "^3.4.2",
|
||||||
"typescript": "^5.7.2",
|
"typescript": "^5.7.2",
|
||||||
"vite": "^6.0.7"
|
"vite": "^6.0.7"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,9 @@
|
|||||||
{
|
{
|
||||||
"include": "#comment"
|
"include": "#comment"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"include": "#function"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"include": "#variables"
|
"include": "#variables"
|
||||||
},
|
},
|
||||||
@@ -14,6 +17,9 @@
|
|||||||
{
|
{
|
||||||
"include": "#keywords"
|
"include": "#keywords"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"include": "#numbers"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"include": "#strings"
|
"include": "#strings"
|
||||||
}
|
}
|
||||||
@@ -38,6 +44,27 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"numbers": {
|
||||||
|
"name": "constant.numeric",
|
||||||
|
"patterns": [
|
||||||
|
{
|
||||||
|
"name": "constant.numeric",
|
||||||
|
"match": "\"\\d+\""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "constant.numeric",
|
||||||
|
"match": "\"\\d+.\\d+\""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "constant.numeric",
|
||||||
|
"match": "\\d+"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "constant.numeric",
|
||||||
|
"match": "\\d+.\\d+"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"types": {
|
"types": {
|
||||||
"patterns": [
|
"patterns": [
|
||||||
{
|
{
|
||||||
@@ -82,6 +109,19 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"function": {
|
||||||
|
"patterns": [
|
||||||
|
{
|
||||||
|
"name": "storage.type.function.cdl",
|
||||||
|
"match": "\\bEVENT\\s+([a-zA-Z_]\\w*)\\b",
|
||||||
|
"captures": {
|
||||||
|
"1": {
|
||||||
|
"name": "entity.name.function"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"comment": {
|
"comment": {
|
||||||
"patterns": [
|
"patterns": [
|
||||||
{
|
{
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "es6",
|
"target": "es2023",
|
||||||
"lib": ["es6"],
|
"lib": ["es2023", "dom"],
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"outDir": "client/out",
|
"outDir": "client/out",
|
||||||
"rootDir": "client",
|
"rootDir": "client",
|
||||||
|
|||||||
+6
-6
@@ -1,17 +1,17 @@
|
|||||||
import { defineConfig } from "vite";
|
import { defineConfig } from "vite"
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
build: {
|
build: {
|
||||||
lib: {
|
lib: {
|
||||||
entry: "./client/src/extension.ts",
|
entry: "./client/src/extension.ts",
|
||||||
formats: ["cjs", "es"],
|
formats: ["cjs", "es"],
|
||||||
fileName: "extension",
|
fileName: "extension"
|
||||||
},
|
},
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
external: ["vscode"],
|
external: ["vscode"]
|
||||||
},
|
},
|
||||||
sourcemap: true,
|
sourcemap: true,
|
||||||
outDir: "client/out/src",
|
outDir: "client/out/src"
|
||||||
},
|
},
|
||||||
plugins: [],
|
plugins: []
|
||||||
});
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user