feat(cdl): add CDL event handler parsing and snippet support
build_and_puplish.yml / build_and_publish (release) Successful in 36s
build_and_puplish.yml / build_and_publish (release) Successful in 36s
This adds a small DSL-aware helper to extract CDL event declarations and generate a ready-to-use snippet. It also extends hover support to show the snippet and parameter hints for CDL events, improving developer productivity. - Generate a MOM event handler scaffold and local vars - Hover shows the generated snippet and mom_ parameter hints
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
import * as vscode from "vscode"
|
||||
import {
|
||||
cdlEventHandlerAtLine,
|
||||
createCdlEventHandlerSnippet
|
||||
} from "./cdlEventHandler"
|
||||
|
||||
export function formatCdlFile(content: string): string {
|
||||
let indentLevel = 0
|
||||
@@ -110,30 +114,33 @@ export function completionHandlerCdl(document: vscode.TextDocument, position: vs
|
||||
}
|
||||
|
||||
export function hoverCdlHandler(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}`
|
||||
const line = document.lineAt(position.line).text
|
||||
const eventMatch = /^\s*EVENT\s+([^\s{]+)/.exec(line)
|
||||
if (eventMatch) {
|
||||
const eventStart = line.indexOf(eventMatch[1], eventMatch.index)
|
||||
const declarationEnd = eventStart + eventMatch[1].length
|
||||
if (position.character <= declarationEnd) {
|
||||
const handler = cdlEventHandlerAtLine(document.getText(), position.line)
|
||||
if (handler) {
|
||||
const markdown = new vscode.MarkdownString()
|
||||
markdown.appendCodeblock(createCdlEventHandlerSnippet(handler), "tcl")
|
||||
return new vscode.Hover(
|
||||
markdown,
|
||||
new vscode.Range(position.line, eventMatch.index, position.line, declarationEnd)
|
||||
)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (hoverText) {
|
||||
return new vscode.Hover(hoverText)
|
||||
const parameterMatch = /^\s*PARAM\s+([^\s{]+)/.exec(line)
|
||||
if (parameterMatch) {
|
||||
const parameterStart = line.indexOf(parameterMatch[1], parameterMatch.index)
|
||||
const parameterEnd = parameterStart + parameterMatch[1].length
|
||||
if (position.character >= parameterStart && position.character <= parameterEnd) {
|
||||
return new vscode.Hover(`mom_${parameterMatch[1].replace(/^mom_/i, "")}`)
|
||||
}
|
||||
}
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user