Pretty much working
This commit is contained in:
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
out
|
||||
dist
|
||||
node_modules
|
||||
.vscode-test/
|
||||
*.vsix
|
||||
5
.vscode-test.mjs
Normal file
5
.vscode-test.mjs
Normal file
@@ -0,0 +1,5 @@
|
||||
import { defineConfig } from '@vscode/test-cli';
|
||||
|
||||
export default defineConfig({
|
||||
files: 'out/test/**/*.test.js',
|
||||
});
|
||||
5
.vscode/extensions.json
vendored
Normal file
5
.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||
// for the documentation about the extensions.json format
|
||||
"recommendations": ["dbaeumer.vscode-eslint", "amodio.tsl-problem-matcher", "ms-vscode.extension-test-runner"]
|
||||
}
|
||||
21
.vscode/launch.json
vendored
Normal file
21
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
// A launch configuration that compiles the extension and then opens it inside a new window
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Run Extension",
|
||||
"type": "extensionHost",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"--extensionDevelopmentPath=${workspaceFolder}"
|
||||
],
|
||||
"outFiles": [
|
||||
"${workspaceFolder}/dist/**/*.js"
|
||||
],
|
||||
"preLaunchTask": "${defaultBuildTask}"
|
||||
}
|
||||
]
|
||||
}
|
||||
13
.vscode/settings.json
vendored
Normal file
13
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
// Place your settings in this file to overwrite default and user settings.
|
||||
{
|
||||
"files.exclude": {
|
||||
"out": false, // set this to true to hide the "out" folder with the compiled JS files
|
||||
"dist": false // set this to true to hide the "dist" folder with the compiled JS files
|
||||
},
|
||||
"search.exclude": {
|
||||
"out": true, // set this to false to include "out" folder in search results
|
||||
"dist": true // set this to false to include "dist" folder in search results
|
||||
},
|
||||
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
|
||||
"typescript.tsc.autoDetect": "off"
|
||||
}
|
||||
40
.vscode/tasks.json
vendored
Normal file
40
.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||
// for the documentation about the tasks.json format
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"type": "npm",
|
||||
"script": "watch",
|
||||
"problemMatcher": "$ts-webpack-watch",
|
||||
"isBackground": true,
|
||||
"presentation": {
|
||||
"reveal": "never",
|
||||
"group": "watchers"
|
||||
},
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "npm",
|
||||
"script": "watch-tests",
|
||||
"problemMatcher": "$tsc-watch",
|
||||
"isBackground": true,
|
||||
"presentation": {
|
||||
"reveal": "never",
|
||||
"group": "watchers"
|
||||
},
|
||||
"group": "build"
|
||||
},
|
||||
{
|
||||
"label": "tasks: watch-tests",
|
||||
"dependsOn": [
|
||||
"npm: watch",
|
||||
"npm: watch-tests"
|
||||
],
|
||||
"problemMatcher": []
|
||||
}
|
||||
]
|
||||
}
|
||||
14
.vscodeignore
Normal file
14
.vscodeignore
Normal file
@@ -0,0 +1,14 @@
|
||||
.vscode/**
|
||||
.vscode-test/**
|
||||
out/**
|
||||
node_modules/**
|
||||
src/**
|
||||
.gitignore
|
||||
.yarnrc
|
||||
webpack.config.js
|
||||
vsc-extension-quickstart.md
|
||||
**/tsconfig.json
|
||||
**/eslint.config.mjs
|
||||
**/*.map
|
||||
**/*.ts
|
||||
**/.vscode-test.*
|
||||
9
CHANGELOG.md
Normal file
9
CHANGELOG.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# Change Log
|
||||
|
||||
All notable changes to the "format-4690" extension will be documented in this file.
|
||||
|
||||
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
- Initial release
|
||||
71
README.md
Normal file
71
README.md
Normal file
@@ -0,0 +1,71 @@
|
||||
# format-4690 README
|
||||
|
||||
This is the README for your extension "format-4690". After writing up a brief description, we recommend including the following sections.
|
||||
|
||||
## Features
|
||||
|
||||
Describe specific features of your extension including screenshots of your extension in action. Image paths are relative to this README file.
|
||||
|
||||
For example if there is an image subfolder under your extension project workspace:
|
||||
|
||||
\!\[feature X\]\(images/feature-x.png\)
|
||||
|
||||
> Tip: Many popular extensions utilize animations. This is an excellent way to show off your extension! We recommend short, focused animations that are easy to follow.
|
||||
|
||||
## Requirements
|
||||
|
||||
If you have any requirements or dependencies, add a section describing those and how to install and configure them.
|
||||
|
||||
## Extension Settings
|
||||
|
||||
Include if your extension adds any VS Code settings through the `contributes.configuration` extension point.
|
||||
|
||||
For example:
|
||||
|
||||
This extension contributes the following settings:
|
||||
|
||||
* `myExtension.enable`: Enable/disable this extension.
|
||||
* `myExtension.thing`: Set to `blah` to do something.
|
||||
|
||||
## Known Issues
|
||||
|
||||
Calling out known issues can help limit users opening duplicate issues against your extension.
|
||||
|
||||
## Release Notes
|
||||
|
||||
Users appreciate release notes as you update your extension.
|
||||
|
||||
### 1.0.0
|
||||
|
||||
Initial release of ...
|
||||
|
||||
### 1.0.1
|
||||
|
||||
Fixed issue #.
|
||||
|
||||
### 1.1.0
|
||||
|
||||
Added features X, Y, and Z.
|
||||
|
||||
---
|
||||
|
||||
## Following extension guidelines
|
||||
|
||||
Ensure that you've read through the extensions guidelines and follow the best practices for creating your extension.
|
||||
|
||||
* [Extension Guidelines](https://code.visualstudio.com/api/references/extension-guidelines)
|
||||
|
||||
## Working with Markdown
|
||||
|
||||
You can author your README using Visual Studio Code. Here are some useful editor keyboard shortcuts:
|
||||
|
||||
* Split the editor (`Cmd+\` on macOS or `Ctrl+\` on Windows and Linux).
|
||||
* Toggle preview (`Shift+Cmd+V` on macOS or `Shift+Ctrl+V` on Windows and Linux).
|
||||
* Press `Ctrl+Space` (Windows, Linux, macOS) to see a list of Markdown snippets.
|
||||
|
||||
## For more information
|
||||
|
||||
* [Visual Studio Code's Markdown Support](http://code.visualstudio.com/docs/languages/markdown)
|
||||
* [Markdown Syntax Reference](https://help.github.com/articles/markdown-basics/)
|
||||
|
||||
**Enjoy!**
|
||||
28
eslint.config.mjs
Normal file
28
eslint.config.mjs
Normal file
@@ -0,0 +1,28 @@
|
||||
import typescriptEslint from "@typescript-eslint/eslint-plugin";
|
||||
import tsParser from "@typescript-eslint/parser";
|
||||
|
||||
export default [{
|
||||
files: ["**/*.ts"],
|
||||
}, {
|
||||
plugins: {
|
||||
"@typescript-eslint": typescriptEslint,
|
||||
},
|
||||
|
||||
languageOptions: {
|
||||
parser: tsParser,
|
||||
ecmaVersion: 2022,
|
||||
sourceType: "module",
|
||||
},
|
||||
|
||||
rules: {
|
||||
"@typescript-eslint/naming-convention": ["warn", {
|
||||
selector: "import",
|
||||
format: ["camelCase", "PascalCase"],
|
||||
}],
|
||||
|
||||
curly: "warn",
|
||||
eqeqeq: "warn",
|
||||
"no-throw-literal": "warn",
|
||||
semi: "warn",
|
||||
},
|
||||
}];
|
||||
27
language-configuration.json
Normal file
27
language-configuration.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"comments": {
|
||||
// symbol used for single line comment. Remove this entry if your language does not support line comments
|
||||
"lineComment": "!"
|
||||
},
|
||||
// symbols used as brackets
|
||||
"brackets": [
|
||||
["{", "}"],
|
||||
["[", "]"],
|
||||
["(", ")"]
|
||||
],
|
||||
// symbols that are auto closed when typing
|
||||
"autoClosingPairs": [
|
||||
["{", "}"],
|
||||
["[", "]"],
|
||||
["(", ")"],
|
||||
["\"", "\""]
|
||||
],
|
||||
// symbols that can be used to surround a selection
|
||||
"surroundingPairs": [
|
||||
["{", "}"],
|
||||
["[", "]"],
|
||||
["(", ")"],
|
||||
["\"", "\""],
|
||||
["'", "'"]
|
||||
]
|
||||
}
|
||||
4750
package-lock.json
generated
Normal file
4750
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
54
package.json
Normal file
54
package.json
Normal file
@@ -0,0 +1,54 @@
|
||||
{
|
||||
"name": "format-4690",
|
||||
"displayName": "format-4690",
|
||||
"description": "Formatter for 4690 BASIC",
|
||||
"version": "0.0.1",
|
||||
"engines": {
|
||||
"vscode": "^1.101.0"
|
||||
},
|
||||
"categories": [
|
||||
"Programming Languages"
|
||||
],
|
||||
"activationEvents": [],
|
||||
"main": "./dist/extension.js",
|
||||
"contributes": {
|
||||
"languages": [{
|
||||
"id": "4690basic",
|
||||
"aliases": ["4690 BASIC", "4690basic"],
|
||||
"extensions": [".BAS", ".J86"],
|
||||
"configuration": "./language-configuration.json"
|
||||
}],
|
||||
"grammars": [
|
||||
{
|
||||
"language": "4690basic",
|
||||
"scopeName": "source.4690basic",
|
||||
"path": "./syntaxes/4690basic.tmLanguage.json"
|
||||
}
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"vscode:prepublish": "npm run package",
|
||||
"compile": "webpack",
|
||||
"watch": "webpack --watch",
|
||||
"package": "webpack --mode production --devtool hidden-source-map",
|
||||
"compile-tests": "tsc -p . --outDir out",
|
||||
"watch-tests": "tsc -p . -w --outDir out",
|
||||
"pretest": "npm run compile-tests && npm run compile && npm run lint",
|
||||
"lint": "eslint src",
|
||||
"test": "vscode-test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/vscode": "^1.101.0",
|
||||
"@types/mocha": "^10.0.10",
|
||||
"@types/node": "20.x",
|
||||
"@typescript-eslint/eslint-plugin": "^8.31.1",
|
||||
"@typescript-eslint/parser": "^8.31.1",
|
||||
"eslint": "^9.25.1",
|
||||
"typescript": "^5.8.3",
|
||||
"ts-loader": "^9.5.2",
|
||||
"webpack": "^5.99.7",
|
||||
"webpack-cli": "^6.0.1",
|
||||
"@vscode/test-cli": "^0.0.10",
|
||||
"@vscode/test-electron": "^2.5.2"
|
||||
}
|
||||
}
|
||||
462
src/extension.ts
Normal file
462
src/extension.ts
Normal file
@@ -0,0 +1,462 @@
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
interface FunctionDefinition {
|
||||
name: string;
|
||||
location: vscode.Location;
|
||||
type: 'FUNCTION' | 'SUB' | 'DEF';
|
||||
}
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
const selector: vscode.DocumentSelector = { language: '4690basic' };
|
||||
|
||||
// Existing formatter provider
|
||||
const formatterProvider: vscode.DocumentFormattingEditProvider = {
|
||||
provideDocumentFormattingEdits(document: vscode.TextDocument): vscode.TextEdit[] {
|
||||
const config = vscode.workspace.getConfiguration('4690basic.format');
|
||||
const indentSize = config.get<number>('indentSize') || 1;
|
||||
const indentUnit = '\t'.repeat(indentSize);
|
||||
|
||||
const edits: vscode.TextEdit[] = [];
|
||||
const lines = document.getText().split('\n');
|
||||
|
||||
let indentLevel = 0;
|
||||
let i = 0;
|
||||
|
||||
// Helper function to remove comments from a line (but preserve line continuations)
|
||||
function removeComments(line: string): string {
|
||||
let inQuotes = false;
|
||||
let quoteChar = '';
|
||||
|
||||
for (let i = 0; i < line.length; i++) {
|
||||
const char = line[i];
|
||||
if (!inQuotes && (char === '"' || char === "'")) {
|
||||
inQuotes = true;
|
||||
quoteChar = char;
|
||||
} else if (inQuotes && char === quoteChar) {
|
||||
inQuotes = false;
|
||||
quoteChar = '';
|
||||
} else if (!inQuotes && char === '!') {
|
||||
return line.substring(0, i).trim();
|
||||
}
|
||||
}
|
||||
return line;
|
||||
}
|
||||
|
||||
// Helper function to check if a line should continue
|
||||
function shouldContinue(line: string, allLines: string[], currentIndex: number): boolean {
|
||||
const withoutComments = removeComments(line).trim();
|
||||
|
||||
// Check for explicit continuation with \
|
||||
if (withoutComments.endsWith('\\')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check for IF without THEN on the same line
|
||||
if (/^\s*IF\b/i.test(withoutComments) && !/\bTHEN\b/i.test(withoutComments)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if current line looks like a continuation of a condition
|
||||
if (/^\s*(AND\b|OR\b|NOT\b|\()/i.test(withoutComments) && currentIndex > 0) {
|
||||
// Look back to see if we're in a continuation chain
|
||||
let prevIndex = currentIndex - 1;
|
||||
while (prevIndex >= 0) {
|
||||
const prevLine = removeComments(allLines[prevIndex]).trim();
|
||||
if (prevLine === '') {
|
||||
prevIndex--;
|
||||
continue;
|
||||
}
|
||||
if (prevLine.endsWith('\\') ||
|
||||
/^\s*IF\b/i.test(prevLine) ||
|
||||
/^\s*(AND\b|OR\b|NOT\b|\()/i.test(prevLine)) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
while (i < lines.length) {
|
||||
const originalLine = lines[i];
|
||||
const trimmedLine = originalLine.trim();
|
||||
|
||||
// Skip empty lines
|
||||
if (trimmedLine === '') {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Collect continuation lines
|
||||
let continuationLines = [originalLine];
|
||||
let j = i;
|
||||
|
||||
while (j < lines.length && shouldContinue(lines[j], lines, j)) {
|
||||
if (j + 1 < lines.length) {
|
||||
j++;
|
||||
continuationLines.push(lines[j]);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Build the complete logical line by joining all parts
|
||||
let logicalParts: string[] = [];
|
||||
for (let k = 0; k < continuationLines.length; k++) {
|
||||
let part = continuationLines[k].trim();
|
||||
part = removeComments(part);
|
||||
if (part.endsWith('\\')) {
|
||||
part = part.slice(0, -1).trim();
|
||||
}
|
||||
if (part) {
|
||||
logicalParts.push(part);
|
||||
}
|
||||
}
|
||||
|
||||
const fullLogical = logicalParts.join(' ').trim();
|
||||
const firstLineTrimmed = removeComments(continuationLines[0]).trim();
|
||||
|
||||
// Simple approach: look for keywords that affect indentation
|
||||
const containsBegin = /\bBEGIN\b/i.test(fullLogical);
|
||||
const containsNext = /\bNEXT\b/i.test(fullLogical);
|
||||
|
||||
const isClosing = /^\s*(END FUNCTION|FEND|END SUB|ENDIF|WEND|NEXT)\b/i.test(firstLineTrimmed) ||
|
||||
containsNext ||
|
||||
(/^\s*ELSE\b/i.test(firstLineTrimmed) && !containsBegin);
|
||||
|
||||
const isOpening = /^\s*(FUNCTION|DEF|SUB|WHILE|FOR)\b/i.test(fullLogical) ||
|
||||
containsBegin;
|
||||
|
||||
// Handle compound statements like ENDIF ELSE BEGIN
|
||||
const isCompoundEndifElse = /\bENDIF\b.*\bELSE\s+BEGIN\b/i.test(fullLogical);
|
||||
const isCompoundEndifElseIf = /\bENDIF\s+ELSE\s+IF\b/i.test(fullLogical) && containsBegin;
|
||||
|
||||
// Adjust indent level for closing statements BEFORE formatting
|
||||
if (isCompoundEndifElse || isCompoundEndifElseIf) {
|
||||
indentLevel = Math.max(indentLevel - 1, 0);
|
||||
} else if (isClosing) {
|
||||
indentLevel = Math.max(indentLevel - 1, 0);
|
||||
}
|
||||
|
||||
// Format all lines in this logical group with current indent level
|
||||
for (let k = 0; k < continuationLines.length; k++) {
|
||||
const lineIndex = i + k;
|
||||
const original = continuationLines[k];
|
||||
const trimmed = original.trim();
|
||||
|
||||
if (trimmed === '') continue;
|
||||
|
||||
const indent = indentUnit.repeat(indentLevel);
|
||||
const formatted = indent + trimmed;
|
||||
|
||||
if (formatted !== original) {
|
||||
const lineRange = document.lineAt(lineIndex).range;
|
||||
edits.push(vscode.TextEdit.replace(lineRange, formatted));
|
||||
}
|
||||
}
|
||||
|
||||
// Adjust indent level for opening statements AFTER formatting
|
||||
if (isCompoundEndifElse || isCompoundEndifElseIf) {
|
||||
indentLevel++;
|
||||
} else if (isOpening) {
|
||||
indentLevel++;
|
||||
}
|
||||
|
||||
// Move to the next logical group
|
||||
i = j + 1;
|
||||
}
|
||||
|
||||
return edits;
|
||||
}
|
||||
};
|
||||
|
||||
// Function to parse function definitions from a document
|
||||
function parseFunctionDefinitions(document: vscode.TextDocument): FunctionDefinition[] {
|
||||
const definitions: FunctionDefinition[] = [];
|
||||
const lines = document.getText().split('\n');
|
||||
const identifierRegex = /(\?|[a-zA-Z])([a-zA-Z0-9#\.]*)[\$#%]?/;
|
||||
|
||||
// Helper function to remove comments from a line
|
||||
function removeComments(line: string): string {
|
||||
let inQuotes = false;
|
||||
let quoteChar = '';
|
||||
|
||||
for (let i = 0; i < line.length; i++) {
|
||||
const char = line[i];
|
||||
if (!inQuotes && (char === '"' || char === "'")) {
|
||||
inQuotes = true;
|
||||
quoteChar = char;
|
||||
} else if (inQuotes && char === quoteChar) {
|
||||
inQuotes = false;
|
||||
quoteChar = '';
|
||||
} else if (!inQuotes && char === '!') {
|
||||
return line.substring(0, i).trim();
|
||||
}
|
||||
}
|
||||
return line;
|
||||
}
|
||||
|
||||
// Helper function to check if a line should continue
|
||||
function shouldContinue(line: string, allLines: string[], currentIndex: number): boolean {
|
||||
const withoutComments = removeComments(line).trim();
|
||||
|
||||
// Check for explicit continuation with \
|
||||
if (withoutComments.endsWith('\\')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// For function definitions, also check if we have incomplete parentheses
|
||||
if (/^\s*(FUNCTION|DEF|SUB)\b/i.test(withoutComments)) {
|
||||
const openParens = (withoutComments.match(/\(/g) || []).length;
|
||||
const closeParens = (withoutComments.match(/\)/g) || []).length;
|
||||
if (openParens > closeParens) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
let i = 0;
|
||||
while (i < lines.length) {
|
||||
const originalLine = lines[i];
|
||||
const trimmedLine = originalLine.trim();
|
||||
|
||||
// Skip empty lines
|
||||
if (trimmedLine === '') {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if this line starts a function definition
|
||||
const functionMatch = /^\s*(FUNCTION|DEF|SUB)\b/i.exec(trimmedLine);
|
||||
if (!functionMatch) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Collect continuation lines for this function definition
|
||||
let continuationLines = [originalLine];
|
||||
let j = i;
|
||||
|
||||
while (j < lines.length && shouldContinue(lines[j], lines, j)) {
|
||||
if (j + 1 < lines.length) {
|
||||
j++;
|
||||
continuationLines.push(lines[j]);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Build the complete logical line by joining all parts
|
||||
let logicalParts: string[] = [];
|
||||
for (let k = 0; k < continuationLines.length; k++) {
|
||||
let part = continuationLines[k].trim();
|
||||
part = removeComments(part);
|
||||
if (part.endsWith('\\')) {
|
||||
part = part.slice(0, -1).trim();
|
||||
}
|
||||
if (part) {
|
||||
logicalParts.push(part);
|
||||
}
|
||||
}
|
||||
|
||||
const fullLogical = logicalParts.join(' ').trim();
|
||||
|
||||
// Check if this is not an external declaration
|
||||
if (!/\bEXTERNAL\s*$/i.test(fullLogical)) {
|
||||
// Extract the function type and name
|
||||
const defType = functionMatch[1].toUpperCase() as 'FUNCTION' | 'SUB' | 'DEF';
|
||||
|
||||
// Find the identifier after the function keyword
|
||||
const afterKeyword = fullLogical.substring(functionMatch[0].length).trim();
|
||||
const nameMatch = identifierRegex.exec(afterKeyword);
|
||||
|
||||
if (nameMatch) {
|
||||
const functionName = nameMatch[0];
|
||||
const position = new vscode.Position(i, originalLine.indexOf(functionName));
|
||||
const location = new vscode.Location(document.uri, position);
|
||||
|
||||
definitions.push({
|
||||
name: functionName,
|
||||
location: location,
|
||||
type: defType
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Move to the next logical group
|
||||
i = j + 1;
|
||||
}
|
||||
|
||||
return definitions;
|
||||
}
|
||||
|
||||
// Definition provider - searches all files in workspace
|
||||
const definitionProvider: vscode.DefinitionProvider = {
|
||||
async provideDefinition(
|
||||
document: vscode.TextDocument,
|
||||
position: vscode.Position,
|
||||
token: vscode.CancellationToken
|
||||
): Promise<vscode.Definition | undefined> {
|
||||
const wordRange = document.getWordRangeAtPosition(position, /(\?|[a-zA-Z])([a-zA-Z0-9#\.]*)[\$#%]?/);
|
||||
if (!wordRange) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const word = document.getText(wordRange);
|
||||
|
||||
// Search in current document first
|
||||
const currentDocDefs = parseFunctionDefinitions(document);
|
||||
const localDef = currentDocDefs.find(def => def.name.toLowerCase() === word.toLowerCase());
|
||||
if (localDef) {
|
||||
return localDef.location;
|
||||
}
|
||||
|
||||
// Search in all workspace files
|
||||
const workspaceFiles = await vscode.workspace.findFiles('**/*.{bas,BAS,j86,J86}');
|
||||
|
||||
for (const fileUri of workspaceFiles) {
|
||||
if (fileUri.toString() === document.uri.toString()) {
|
||||
continue; // Skip current document as we already searched it
|
||||
}
|
||||
|
||||
try {
|
||||
const doc = await vscode.workspace.openTextDocument(fileUri);
|
||||
const definitions = parseFunctionDefinitions(doc);
|
||||
const definition = definitions.find(def => def.name.toLowerCase() === word.toLowerCase());
|
||||
|
||||
if (definition) {
|
||||
return definition.location;
|
||||
}
|
||||
} catch (error) {
|
||||
// Skip files that can't be opened
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
// Workspace symbol provider - only searches open documents
|
||||
const workspaceSymbolProvider: vscode.WorkspaceSymbolProvider = {
|
||||
async provideWorkspaceSymbols(
|
||||
query: string,
|
||||
token: vscode.CancellationToken
|
||||
): Promise<vscode.SymbolInformation[]> {
|
||||
const symbols: vscode.SymbolInformation[] = [];
|
||||
|
||||
// Only search in currently open documents
|
||||
for (const document of vscode.workspace.textDocuments) {
|
||||
// Only search in files with our language ID
|
||||
if (document.languageId === '4690basic') {
|
||||
const definitions = parseFunctionDefinitions(document);
|
||||
|
||||
for (const def of definitions) {
|
||||
if (!query || def.name.toLowerCase().includes(query.toLowerCase())) {
|
||||
const symbolKind = def.type === 'SUB' ? vscode.SymbolKind.Method : vscode.SymbolKind.Function;
|
||||
const symbol = new vscode.SymbolInformation(
|
||||
def.name,
|
||||
symbolKind,
|
||||
'',
|
||||
def.location
|
||||
);
|
||||
symbols.push(symbol);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return symbols;
|
||||
}
|
||||
};
|
||||
|
||||
// Document symbol provider (for outline view)
|
||||
const documentSymbolProvider: vscode.DocumentSymbolProvider = {
|
||||
provideDocumentSymbols(
|
||||
document: vscode.TextDocument,
|
||||
token: vscode.CancellationToken
|
||||
): vscode.DocumentSymbol[] {
|
||||
const definitions = parseFunctionDefinitions(document);
|
||||
const symbols: vscode.DocumentSymbol[] = [];
|
||||
|
||||
for (const def of definitions) {
|
||||
const symbolKind = def.type === 'SUB' ? vscode.SymbolKind.Method : vscode.SymbolKind.Function;
|
||||
const range = new vscode.Range(def.location.range.start, def.location.range.start);
|
||||
|
||||
const symbol = new vscode.DocumentSymbol(
|
||||
def.name,
|
||||
def.type,
|
||||
symbolKind,
|
||||
range,
|
||||
range
|
||||
);
|
||||
symbols.push(symbol);
|
||||
}
|
||||
|
||||
return symbols;
|
||||
}
|
||||
};
|
||||
|
||||
// Hover provider to help VS Code recognize symbols and show proper highlighting
|
||||
const hoverProvider: vscode.HoverProvider = {
|
||||
provideHover(
|
||||
document: vscode.TextDocument,
|
||||
position: vscode.Position,
|
||||
token: vscode.CancellationToken
|
||||
): vscode.Hover | undefined {
|
||||
const wordRange = document.getWordRangeAtPosition(position, /(\?|[a-zA-Z])([a-zA-Z0-9#\.]*)[\$#%]?/);
|
||||
if (!wordRange) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const word = document.getText(wordRange);
|
||||
|
||||
// Search for the function definition in current document
|
||||
const currentDocDefs = parseFunctionDefinitions(document);
|
||||
let definition = currentDocDefs.find(def => def.name.toLowerCase() === word.toLowerCase());
|
||||
|
||||
// If not found locally, search in open documents
|
||||
if (!definition) {
|
||||
for (const openDoc of vscode.workspace.textDocuments) {
|
||||
if (openDoc.uri.toString() === document.uri.toString()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (openDoc.languageId === '4690basic') {
|
||||
const definitions = parseFunctionDefinitions(openDoc);
|
||||
definition = definitions.find(def => def.name.toLowerCase() === word.toLowerCase());
|
||||
|
||||
if (definition) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (definition) {
|
||||
const typeLabel = definition.type === 'SUB' ? 'Subroutine' : 'Function';
|
||||
const content = new vscode.MarkdownString();
|
||||
content.appendCodeblock(`${definition.type} ${definition.name}`, '4690basic');
|
||||
content.appendText(`\n${typeLabel}: ${definition.name}`);
|
||||
|
||||
return new vscode.Hover(content, wordRange);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
// Register all providers
|
||||
context.subscriptions.push(
|
||||
vscode.languages.registerDocumentFormattingEditProvider(selector, formatterProvider),
|
||||
vscode.languages.registerDefinitionProvider(selector, definitionProvider),
|
||||
vscode.languages.registerWorkspaceSymbolProvider(workspaceSymbolProvider),
|
||||
vscode.languages.registerDocumentSymbolProvider(selector, documentSymbolProvider),
|
||||
vscode.languages.registerHoverProvider(selector, hoverProvider)
|
||||
);
|
||||
}
|
||||
|
||||
export function deactivate() {}
|
||||
15
src/test/extension.test.ts
Normal file
15
src/test/extension.test.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import * as assert from 'assert';
|
||||
|
||||
// You can import and use all API from the 'vscode' module
|
||||
// as well as import your extension to test it
|
||||
import * as vscode from 'vscode';
|
||||
// import * as myExtension from '../../extension';
|
||||
|
||||
suite('Extension Test Suite', () => {
|
||||
vscode.window.showInformationMessage('Start all tests.');
|
||||
|
||||
test('Sample test', () => {
|
||||
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
|
||||
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
|
||||
});
|
||||
});
|
||||
841
syntaxes/4690basic.tmLanguage.json
Normal file
841
syntaxes/4690basic.tmLanguage.json
Normal file
@@ -0,0 +1,841 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
|
||||
"name": "4690 BASIC",
|
||||
"patterns": [
|
||||
{
|
||||
"name": "string.quoted.double",
|
||||
"begin": "\"",
|
||||
"end": "\"",
|
||||
"patterns": [
|
||||
{
|
||||
"match": ".",
|
||||
"name": "string.quoted.double"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "string.regexp",
|
||||
"match": "\\b[\\w\\.]+:"
|
||||
},
|
||||
{
|
||||
"include": "#comments"
|
||||
},
|
||||
{
|
||||
"include": "#function-decl"
|
||||
},
|
||||
{
|
||||
"include": "#function-end"
|
||||
},
|
||||
{
|
||||
"include": "#subroutine-decl"
|
||||
},
|
||||
{
|
||||
"include": "#subroutine-end"
|
||||
},
|
||||
{
|
||||
"include": "#integer-decl"
|
||||
},
|
||||
{
|
||||
"include": "#string-decl"
|
||||
},
|
||||
{
|
||||
"include": "#real-decl"
|
||||
},
|
||||
{
|
||||
"include": "#math-function"
|
||||
},
|
||||
{
|
||||
"include": "#string-function"
|
||||
},
|
||||
{
|
||||
"include": "#variable-assignment"
|
||||
},
|
||||
{
|
||||
"include": "#if-statement"
|
||||
},
|
||||
{
|
||||
"include": "#if-statement-end"
|
||||
},
|
||||
{
|
||||
"include": "#for-statement"
|
||||
},
|
||||
{
|
||||
"include": "#arithmetic-operator"
|
||||
},
|
||||
{
|
||||
"include": "#relational-operator"
|
||||
},
|
||||
{
|
||||
"include": "#logical-operator"
|
||||
},
|
||||
{
|
||||
"include": "#line-continuation"
|
||||
},
|
||||
{
|
||||
"include": "#keywords"
|
||||
},
|
||||
{
|
||||
"include": "#strings"
|
||||
},
|
||||
{
|
||||
"include": "#stmt-w-parameters"
|
||||
},
|
||||
{
|
||||
"include": "#access-stmt"
|
||||
},
|
||||
{
|
||||
"include": "#dim-stmt"
|
||||
},
|
||||
{
|
||||
"include": "#compiler-directives"
|
||||
},
|
||||
{
|
||||
"include": "#on-error"
|
||||
},
|
||||
{
|
||||
"include": "#open-close"
|
||||
},
|
||||
{
|
||||
"include": "#number-literal"
|
||||
},
|
||||
{
|
||||
"include": "#identifier"
|
||||
}
|
||||
],
|
||||
"repository": {
|
||||
"line-continuation": {
|
||||
"name": "meta.line.continuation",
|
||||
"match": "\\\\(.*)\\n",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "comment"
|
||||
}
|
||||
}
|
||||
},
|
||||
"comments": {
|
||||
"patterns": [
|
||||
{
|
||||
"name": "comment.line",
|
||||
"match": "!.*|REM.*|REMARK.*"
|
||||
}
|
||||
]
|
||||
},
|
||||
"function-decl": {
|
||||
"name": "meta.function",
|
||||
"begin": "(?i)\\b(FUNCTION|DEF)\\s+((\\?|[a-zA-Z])([a-zA-Z0-9#.]*)[\\$#%]?)",
|
||||
"beginCaptures": {
|
||||
"1": {
|
||||
"name": "storage.type.function"
|
||||
},
|
||||
"2": {
|
||||
"name": "entity.name.function"
|
||||
}
|
||||
},
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#parameter-list"
|
||||
},
|
||||
{
|
||||
"include": "#fun-sub-modifier"
|
||||
},
|
||||
{
|
||||
"include": "#line-continuation"
|
||||
},
|
||||
{
|
||||
"include": "#comments"
|
||||
}
|
||||
],
|
||||
"end": "(?<!\\\\)\\n"
|
||||
},
|
||||
"function-end": {
|
||||
"name": "keyword.control",
|
||||
"match": "(?i)(FEND|END FUNCTION)"
|
||||
},
|
||||
"fun-sub-modifier": {
|
||||
"name": "storage.modifer",
|
||||
"match": "PUBLIC|public|EXTERNAL|external"
|
||||
},
|
||||
"subroutine-decl": {
|
||||
"name": "meta.subroutine",
|
||||
"begin": "\\b(SUB|sub)\\s+((\\?|[a-zA-Z])([a-zA-Z0-9#.]*)[\\$#%]?)",
|
||||
"beginCaptures": {
|
||||
"1": {
|
||||
"name": "storage.type.function"
|
||||
},
|
||||
"2": {
|
||||
"name": "entity.name.function"
|
||||
}
|
||||
},
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#parameter-list"
|
||||
},
|
||||
{
|
||||
"include": "#fun-sub-modifier"
|
||||
},
|
||||
{
|
||||
"include": "#line-continuation"
|
||||
},
|
||||
{
|
||||
"include": "#comments"
|
||||
}
|
||||
],
|
||||
"end": "(?<!\\\\)\\n"
|
||||
},
|
||||
"subroutine-end": {
|
||||
"name": "keyword.control",
|
||||
"match": "END SUB|end sub"
|
||||
},
|
||||
"integer-decl": {
|
||||
"begin": "(INTEGER|integer)((\\*)(1|2|4))?",
|
||||
"beginCaptures": {
|
||||
"1": {
|
||||
"name": "storage.type"
|
||||
},
|
||||
"3": {
|
||||
"name": "keyword.operator.arithmetic"
|
||||
},
|
||||
"4": {
|
||||
"name": "constant.numeric"
|
||||
}
|
||||
},
|
||||
"patterns": [
|
||||
{
|
||||
"name": "keyword.operator",
|
||||
"match": "GLOBAL|global"
|
||||
},
|
||||
{
|
||||
"name": "entity.name.function",
|
||||
"match": "(\\?|[a-zA-Z])([a-zA-Z0-9#.]*)([\\$#%])?",
|
||||
"captures": {
|
||||
"3": {
|
||||
"name": "keyword.operator"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "punctuation.separator.parameter",
|
||||
"match": ","
|
||||
},
|
||||
{
|
||||
"match": "\\s+",
|
||||
"name": "text.whitespace"
|
||||
},
|
||||
{
|
||||
"match": "\\\\(.*)$",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "comment"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"end": "(?<!\\\\.*?)\\n|(!.*)",
|
||||
"endCaptures": {
|
||||
"1": {
|
||||
"name": "comment"
|
||||
}
|
||||
}
|
||||
},
|
||||
"string-decl": {
|
||||
"begin": "(?i)STRING\\s+",
|
||||
"beginCaptures": {
|
||||
"0": {
|
||||
"name": "storage.type"
|
||||
}
|
||||
},
|
||||
"patterns": [
|
||||
{
|
||||
"name": "keyword.operator",
|
||||
"match": "GLOBAL|global"
|
||||
},
|
||||
{
|
||||
"name": "entity.name.function",
|
||||
"match": "(\\?|[a-zA-Z])([a-zA-Z0-9#.]*)([\\$#%])?",
|
||||
"captures": {
|
||||
"3": {
|
||||
"name": "keyword.operator"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "punctuation.separator.parameter",
|
||||
"match": ","
|
||||
},
|
||||
{
|
||||
"match": "\\s+",
|
||||
"name": "text.whitespace"
|
||||
},
|
||||
{
|
||||
"match": "\\\\(.*)$",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "comment"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"end": "(?<!\\\\.*?)\\n|(!.*)",
|
||||
"endCaptures": {
|
||||
"1": {
|
||||
"name": "comment"
|
||||
}
|
||||
}
|
||||
},
|
||||
"real-decl": {
|
||||
"begin": "REAL|real",
|
||||
"beginCaptures": {
|
||||
"0": {
|
||||
"name": "storage.type"
|
||||
}
|
||||
},
|
||||
"patterns": [
|
||||
{
|
||||
"name": "keyword.operator",
|
||||
"match": "GLOBAL|global"
|
||||
},
|
||||
{
|
||||
"name": "entity.name.function",
|
||||
"match": "(\\?|[a-zA-Z])([a-zA-Z0-9#.]*)([\\$#%])?",
|
||||
"captures": {
|
||||
"3": {
|
||||
"name": "keyword.operator"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "punctuation.separator.parameter",
|
||||
"match": ","
|
||||
},
|
||||
{
|
||||
"match": "\\s+",
|
||||
"name": "text.whitespace"
|
||||
},
|
||||
{
|
||||
"match": "\\\\(.*)$",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "comment"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"end": "(?<!\\\\.*?)\\n|(!.*)",
|
||||
"endCaptures": {
|
||||
"1": {
|
||||
"name": "comment"
|
||||
}
|
||||
}
|
||||
},
|
||||
"parameter-list": {
|
||||
"name": "meta.parameters",
|
||||
"begin": "\\(",
|
||||
"beginCaptures": {
|
||||
"0": {
|
||||
"name": "punctuation.definition.parameters.begin"
|
||||
}
|
||||
},
|
||||
"end": "\\)",
|
||||
"endCaptures": {
|
||||
"0": {
|
||||
"name": "punctuation.definition.parameters.end"
|
||||
}
|
||||
},
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#single-param"
|
||||
},
|
||||
{
|
||||
"name": "punctuation.separator.parameter",
|
||||
"match": ","
|
||||
},
|
||||
{
|
||||
"match": "\\s+",
|
||||
"name": "text.whitespace"
|
||||
}
|
||||
]
|
||||
},
|
||||
"single-param": {
|
||||
"patterns": [
|
||||
{
|
||||
"name": "variable.parameter",
|
||||
"match": "(\\?|[a-zA-Z])([a-zA-Z0-9#.]*)[\\$#%]?"
|
||||
}
|
||||
]
|
||||
},
|
||||
"math-function": {
|
||||
"name": "support.function.arithmetic",
|
||||
"match": "(?i)\\b(ABS|CHR\\$|FLOAT|INT%?|MOD|PEEK|SGN|SHIFT|STR\\$|TAB)\\b[^%\\$\\.]"
|
||||
},
|
||||
"variable-assignment": {
|
||||
"name": "meta.assignment",
|
||||
"match": "^\\s*(\\?|[a-zA-Z])([a-zA-Z0-9#.]*)([\\$#%])?\\s+(=)",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "variable.name"
|
||||
},
|
||||
"2": {
|
||||
"name": "variable.name"
|
||||
},
|
||||
"3": {
|
||||
"name": "keyword.operator"
|
||||
},
|
||||
"4": {
|
||||
"name": "keyword.operator.arithmetic"
|
||||
}
|
||||
}
|
||||
},
|
||||
"numeric-expression": {
|
||||
"name": "meta.expression.numeric",
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#number-literal"
|
||||
},
|
||||
{
|
||||
"include": "#arithmetic-operator"
|
||||
},
|
||||
{
|
||||
"name": "variable.name",
|
||||
"match": "(\\?|[a-zA-Z])([a-zA-Z0-9#.]*)%?"
|
||||
},
|
||||
{
|
||||
"match": "\\s+",
|
||||
"name": "text.whitespace"
|
||||
}
|
||||
]
|
||||
},
|
||||
"identifier": {
|
||||
"patterns": [
|
||||
{
|
||||
"name": "variable.name",
|
||||
"match": "\\b(\\?|[a-zA-Z])([a-zA-Z0-9#.]*)[\\$#%]?\\b"
|
||||
}
|
||||
]
|
||||
},
|
||||
"number-literal": {
|
||||
"patterns": [
|
||||
{
|
||||
"name": "constant.numeric",
|
||||
"match": "(?i)\\b([+-]?[0-9.]+)(E[+-]?[0-9]+)?[hb]?\\b"
|
||||
}
|
||||
]
|
||||
},
|
||||
"arithmetic-operator": {
|
||||
"name": "keyword.operator.arithmetic",
|
||||
"match": "[\\+-\\/\\^\\*]"
|
||||
},
|
||||
"relational-operator": {
|
||||
"name": "keyword.operator.relational",
|
||||
"match": "(?i)(<=|<>|<|=>|>|=)|\\b(LT|LE|GT|GE|EQ|NE)\\b"
|
||||
},
|
||||
"logical-operator": {
|
||||
"name": "keyword.operator.logical",
|
||||
"match": "\\b(NOT|AND|OR|XOR)\\b"
|
||||
},
|
||||
"string-operator": {
|
||||
"name": "keyword.operator",
|
||||
"match": "[+]"
|
||||
},
|
||||
"string-function": {
|
||||
"begin": "(?i)\\b(ASC|LEN|PACK\\$|TRANSLATE\\$|UCASE\\$|UNPACK\\$|VAL|MID\\$|LEFT\\$|RIGHT\\$|MATCH)\\b",
|
||||
"beginCaptures": {
|
||||
"1": {
|
||||
"name": "support.function.string"
|
||||
},
|
||||
"0": {
|
||||
"name": "meta.function-call.begin"
|
||||
}
|
||||
},
|
||||
"end": "\\(",
|
||||
"endCaptures": {
|
||||
"0": {
|
||||
"name": "punctuation.parameters.start"
|
||||
}
|
||||
}
|
||||
},
|
||||
"string-expression": {
|
||||
"name": "meta.expression.string",
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#strings"
|
||||
},
|
||||
{
|
||||
"include": "#string-operator"
|
||||
},
|
||||
{
|
||||
"include": "#identifier"
|
||||
},
|
||||
{
|
||||
"name": "\\s+",
|
||||
"match": "text.whitespace"
|
||||
}
|
||||
]
|
||||
},
|
||||
"logical-expression": {
|
||||
"name": "meta.expression.logical",
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#strings"
|
||||
},
|
||||
{
|
||||
"include": "#logical-operator"
|
||||
},
|
||||
{
|
||||
"include": "#identifier"
|
||||
},
|
||||
{
|
||||
"include": "#number-literal"
|
||||
},
|
||||
{
|
||||
"name": "variable.name",
|
||||
"match": "(\\?|[a-zA-Z])([a-zA-Z0-9#.]*)%?"
|
||||
},
|
||||
{
|
||||
"name": "\\s+",
|
||||
"match": "text.whitespace"
|
||||
}
|
||||
]
|
||||
},
|
||||
"relational-expression": {
|
||||
"name": "meta.expression.relational",
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#strings"
|
||||
},
|
||||
{
|
||||
"include": "#relational-operator"
|
||||
},
|
||||
{
|
||||
"include": "#identifier"
|
||||
},
|
||||
{
|
||||
"include": "#number-literal"
|
||||
},
|
||||
{
|
||||
"name": "variable.name",
|
||||
"match": "(\\?|[a-zA-Z])([a-zA-Z0-9#.]*)%?"
|
||||
},
|
||||
{
|
||||
"name": "\\s+",
|
||||
"match": "text.whitespace"
|
||||
}
|
||||
]
|
||||
},
|
||||
"general-expression": {
|
||||
"name": "meta.expression",
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#logical-expression"
|
||||
},
|
||||
{
|
||||
"include": "#relational-expression"
|
||||
},
|
||||
{
|
||||
"include": "#numeric-expression"
|
||||
},
|
||||
{
|
||||
"include": "#string-expression"
|
||||
}
|
||||
]
|
||||
},
|
||||
"keywords": {
|
||||
"patterns": [
|
||||
{
|
||||
"name": "keyword.control",
|
||||
"match": "(?i)\\b(GOSUB|RETURN|GOTO|WHILE|WEND|NEXT|ON|ERROR|STOP|RANDOMIZE|CHAIN|COMMON|CALL|EXIT SUB|FORM)\\b[^%\\$\\.]"
|
||||
},
|
||||
{
|
||||
"name": "support.function",
|
||||
"match": "(?i)\\b(NULL|TRUE|FALSE|READ|WRITE|KEY)\\b[^%\\$\\.]"
|
||||
}
|
||||
]
|
||||
},
|
||||
"strings": {
|
||||
"name": "string.quoted.double.4690basic",
|
||||
"begin": "\"",
|
||||
"end": "\"",
|
||||
"patterns": [
|
||||
{
|
||||
"name": "constant.character.escape.4690basic",
|
||||
"match": "\\\\."
|
||||
}
|
||||
]
|
||||
},
|
||||
"single-stmts": {
|
||||
"name": "support.function",
|
||||
"match": "(COMMAND$|CONCHAR%|CONSOLE|DATE$)"
|
||||
},
|
||||
"stmt-w-parameters": {
|
||||
"begin": "(?i)\\b(ASSIGNKEY|CHDIR|COMMON|CLEARS|DATA|DELETE|DELREC|GOSUB|GOTO|INPUT( LINE)?|MKDIR|NEXT|POINT|POKE|PUT|PUTLONG|READ MATRIX|RESUME|RMDIR|USE|WAIT)\\b",
|
||||
"beginCaptures": {
|
||||
"0": {
|
||||
"name": "keyword.other"
|
||||
}
|
||||
},
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#io-session"
|
||||
},
|
||||
{
|
||||
"include": "#string-expression"
|
||||
},
|
||||
{
|
||||
"include": "#numeric-expression"
|
||||
},
|
||||
{
|
||||
"include": "#identifier"
|
||||
},
|
||||
{
|
||||
"name": "punctuation.separator.parameter",
|
||||
"match": ","
|
||||
},
|
||||
{
|
||||
"name": "punctuation.separator.option",
|
||||
"match": ";"
|
||||
},
|
||||
{
|
||||
"match": "\\s+",
|
||||
"name": "text.whitespace"
|
||||
}
|
||||
],
|
||||
"end": "$"
|
||||
},
|
||||
"open-close": {
|
||||
"name": "support.function",
|
||||
"match": "(?i)OPEN|CLOSE|KEYED|RECL|AS"
|
||||
},
|
||||
"access-stmt": {
|
||||
"match": "(ACCESS)\\s+((NOREAD|NOWRITE|NODEL)(\\s*,\\s*(NOREAD|NOWRITE|NODEL)){0,2})",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "support.function"
|
||||
},
|
||||
"2": {
|
||||
"name": "constant.language"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dim-stmt": {
|
||||
"begin": "(?i)DIM\\s+",
|
||||
"beginCaptures": {
|
||||
"0": {
|
||||
"name": "support.function"
|
||||
}
|
||||
},
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#identifier"
|
||||
},
|
||||
{
|
||||
"include": "#dim-subscript"
|
||||
},
|
||||
{
|
||||
"include": "#line-continuation"
|
||||
},
|
||||
{
|
||||
"include": "#comments"
|
||||
}
|
||||
],
|
||||
"end": "\\)|$"
|
||||
},
|
||||
"dim-subscript": {
|
||||
"begin": "\\(",
|
||||
"beginCaptures": {
|
||||
"0": {
|
||||
"name": "meta.function-call.begin"
|
||||
}
|
||||
},
|
||||
"patterns": [
|
||||
{
|
||||
"name": "constant.numeric",
|
||||
"match": "\\d"
|
||||
},
|
||||
{
|
||||
"include": "#identifier"
|
||||
},
|
||||
{
|
||||
"name": "punctuation.separator.parameter",
|
||||
"match": ","
|
||||
},
|
||||
{
|
||||
"name": "text.whitespace",
|
||||
"match": "\\s+"
|
||||
}
|
||||
],
|
||||
"end": "\\)",
|
||||
"endCaptures": {
|
||||
"0": {
|
||||
"name": "punctuation.parameters.end"
|
||||
}
|
||||
}
|
||||
},
|
||||
"compiler-directives": {
|
||||
"name": "keyword.other",
|
||||
"match": "(%)(INCLUDE|include|DEBUG|debug|ENVIRON|environ|NOLIST|nolist|LIST|list|EJECT|eject|PAGE|page)\\s+([^!\\r\\n]*)",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "keyword.operator"
|
||||
},
|
||||
"2": {
|
||||
"name": "keyword.other"
|
||||
},
|
||||
"3": {
|
||||
"name": "constant.numeric"
|
||||
}
|
||||
}
|
||||
},
|
||||
"if-statement": {
|
||||
"name": "meta.if",
|
||||
"begin": "(?i)\\b(IF)",
|
||||
"beginCaptures": {
|
||||
"0": {
|
||||
"name": "keyword.control"
|
||||
}
|
||||
},
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#math-function"
|
||||
},
|
||||
{
|
||||
"include": "#string-function"
|
||||
},
|
||||
{
|
||||
"include": "#number-literal"
|
||||
},
|
||||
{
|
||||
"include": "#number-literal"
|
||||
},
|
||||
{
|
||||
"include": "#arithmetic-operator"
|
||||
},
|
||||
{
|
||||
"include": "#relational-operator"
|
||||
},
|
||||
{
|
||||
"include": "#logical-operator"
|
||||
},
|
||||
{
|
||||
"include": "#keywords"
|
||||
},
|
||||
{
|
||||
"include": "#strings"
|
||||
},
|
||||
{
|
||||
"name": "keyword.control",
|
||||
"match": "(?i)THEN"
|
||||
},
|
||||
{
|
||||
"name": "keyword.control",
|
||||
"match": "(?i)ELSE"
|
||||
},
|
||||
{
|
||||
"name": "keyword.control",
|
||||
"match": "(?i)(BEGIN)"
|
||||
},
|
||||
{
|
||||
"include": "#line-continuation"
|
||||
},
|
||||
{
|
||||
"include": "#comments"
|
||||
},
|
||||
{
|
||||
"match": "\\s+",
|
||||
"name": "text.whitespace"
|
||||
}
|
||||
],
|
||||
"end": "(?<!\\\\)\\n"
|
||||
},
|
||||
"if-statement-end": {
|
||||
"name": "meta.if.end",
|
||||
"begin": "(?i)ENDIF",
|
||||
"beginCaptures": {
|
||||
"0": {
|
||||
"name": "keyword.control"
|
||||
}
|
||||
},
|
||||
"patterns": [
|
||||
{
|
||||
"name": "keyword.control",
|
||||
"match": "ELSE"
|
||||
},
|
||||
{
|
||||
"include": "#math-function"
|
||||
},
|
||||
{
|
||||
"include": "#string-function"
|
||||
},
|
||||
{
|
||||
"include": "#number-literal"
|
||||
},
|
||||
{
|
||||
"include": "#arithmetic-operator"
|
||||
},
|
||||
{
|
||||
"include": "#relational-operator"
|
||||
},
|
||||
{
|
||||
"include": "#logical-operator"
|
||||
},
|
||||
{
|
||||
"include": "#keywords"
|
||||
},
|
||||
{
|
||||
"include": "#strings"
|
||||
},
|
||||
{
|
||||
"name": "keyword.control",
|
||||
"match": "THEN|then"
|
||||
},
|
||||
{
|
||||
"name": "keyword.control",
|
||||
"match": "(?i)BEGIN"
|
||||
},
|
||||
{
|
||||
"name": "keyword.control",
|
||||
"match": "(?i)ELSE"
|
||||
},
|
||||
{
|
||||
"name": "keyword.control",
|
||||
"match": "(?i)IF"
|
||||
},
|
||||
{
|
||||
"include": "#line-continuation"
|
||||
},
|
||||
{
|
||||
"include": "#comments"
|
||||
}
|
||||
],
|
||||
"end": "(?<!\\\\)\\n"
|
||||
},
|
||||
"for-statement": {
|
||||
"name": "meta.for",
|
||||
"begin": "(?i)\\bFOR\\s+",
|
||||
"beginCaptures": {
|
||||
"0": { "name": "keyword.control" }
|
||||
},
|
||||
"patterns": [
|
||||
{
|
||||
"name": "keyword.control",
|
||||
"match": "(?i)\\bTO\\b"
|
||||
},
|
||||
{
|
||||
"include": "#relational-expression"
|
||||
},
|
||||
{
|
||||
"include": "#arithmetic-expression"
|
||||
},
|
||||
{
|
||||
"include": "#variable-assignment"
|
||||
},
|
||||
{
|
||||
"include": "#identifier"
|
||||
},
|
||||
{
|
||||
"include": "#number-literal"
|
||||
}
|
||||
],
|
||||
"end": "(?<!\\\\)\\n"
|
||||
}
|
||||
},
|
||||
"scopeName": "source.4690basic"
|
||||
}
|
||||
16
tsconfig.json
Normal file
16
tsconfig.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "Node16",
|
||||
"target": "ES2022",
|
||||
"lib": [
|
||||
"ES2022"
|
||||
],
|
||||
"sourceMap": true,
|
||||
"rootDir": "src",
|
||||
"strict": true, /* enable all strict type-checking options */
|
||||
/* Additional Checks */
|
||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
}
|
||||
}
|
||||
48
vsc-extension-quickstart.md
Normal file
48
vsc-extension-quickstart.md
Normal file
@@ -0,0 +1,48 @@
|
||||
# Welcome to your VS Code Extension
|
||||
|
||||
## What's in the folder
|
||||
|
||||
* This folder contains all of the files necessary for your extension.
|
||||
* `package.json` - this is the manifest file in which you declare your extension and command.
|
||||
* The sample plugin registers a command and defines its title and command name. With this information VS Code can show the command in the command palette. It doesn’t yet need to load the plugin.
|
||||
* `src/extension.ts` - this is the main file where you will provide the implementation of your command.
|
||||
* The file exports one function, `activate`, which is called the very first time your extension is activated (in this case by executing the command). Inside the `activate` function we call `registerCommand`.
|
||||
* We pass the function containing the implementation of the command as the second parameter to `registerCommand`.
|
||||
|
||||
## Setup
|
||||
|
||||
* install the recommended extensions (amodio.tsl-problem-matcher, ms-vscode.extension-test-runner, and dbaeumer.vscode-eslint)
|
||||
|
||||
|
||||
## Get up and running straight away
|
||||
|
||||
* Press `F5` to open a new window with your extension loaded.
|
||||
* Run your command from the command palette by pressing (`Ctrl+Shift+P` or `Cmd+Shift+P` on Mac) and typing `Hello World`.
|
||||
* Set breakpoints in your code inside `src/extension.ts` to debug your extension.
|
||||
* Find output from your extension in the debug console.
|
||||
|
||||
## Make changes
|
||||
|
||||
* You can relaunch the extension from the debug toolbar after changing code in `src/extension.ts`.
|
||||
* You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes.
|
||||
|
||||
|
||||
## Explore the API
|
||||
|
||||
* You can open the full set of our API when you open the file `node_modules/@types/vscode/index.d.ts`.
|
||||
|
||||
## Run tests
|
||||
|
||||
* Install the [Extension Test Runner](https://marketplace.visualstudio.com/items?itemName=ms-vscode.extension-test-runner)
|
||||
* Run the "watch" task via the **Tasks: Run Task** command. Make sure this is running, or tests might not be discovered.
|
||||
* Open the Testing view from the activity bar and click the Run Test" button, or use the hotkey `Ctrl/Cmd + ; A`
|
||||
* See the output of the test result in the Test Results view.
|
||||
* Make changes to `src/test/extension.test.ts` or create new test files inside the `test` folder.
|
||||
* The provided test runner will only consider files matching the name pattern `**.test.ts`.
|
||||
* You can create folders inside the `test` folder to structure your tests any way you want.
|
||||
|
||||
## Go further
|
||||
|
||||
* Reduce the extension size and improve the startup time by [bundling your extension](https://code.visualstudio.com/api/working-with-extensions/bundling-extension).
|
||||
* [Publish your extension](https://code.visualstudio.com/api/working-with-extensions/publishing-extension) on the VS Code extension marketplace.
|
||||
* Automate builds by setting up [Continuous Integration](https://code.visualstudio.com/api/working-with-extensions/continuous-integration).
|
||||
48
webpack.config.js
Normal file
48
webpack.config.js
Normal file
@@ -0,0 +1,48 @@
|
||||
//@ts-check
|
||||
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
|
||||
//@ts-check
|
||||
/** @typedef {import('webpack').Configuration} WebpackConfig **/
|
||||
|
||||
/** @type WebpackConfig */
|
||||
const extensionConfig = {
|
||||
target: 'node', // VS Code extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/
|
||||
mode: 'none', // this leaves the source code as close as possible to the original (when packaging we set this to 'production')
|
||||
|
||||
entry: './src/extension.ts', // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/
|
||||
output: {
|
||||
// the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/
|
||||
path: path.resolve(__dirname, 'dist'),
|
||||
filename: 'extension.js',
|
||||
libraryTarget: 'commonjs2'
|
||||
},
|
||||
externals: {
|
||||
vscode: 'commonjs vscode' // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/
|
||||
// modules added here also need to be added in the .vscodeignore file
|
||||
},
|
||||
resolve: {
|
||||
// support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader
|
||||
extensions: ['.ts', '.js']
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.ts$/,
|
||||
exclude: /node_modules/,
|
||||
use: [
|
||||
{
|
||||
loader: 'ts-loader'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
devtool: 'nosources-source-map',
|
||||
infrastructureLogging: {
|
||||
level: "log", // enables logging required for problem matchers
|
||||
},
|
||||
};
|
||||
module.exports = [ extensionConfig ];
|
||||
Reference in New Issue
Block a user