Skip to content

Commit

Permalink
Add mf6-ify extension command to manually set language mode (#36)
Browse files Browse the repository at this point in the history
* Add @types/vscode and typescript as dev dependency

* Add compiling of typescript as a pre-launch task

* Add mf6-ify extension command

* Ignore out directory in git, prettier, packaging

* Describe mf6-ify command usage in readme
  • Loading branch information
martclanor authored Feb 16, 2025
1 parent b5d7a47 commit c52bcc9
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
*.vsix
.vscode/settings.json
data/
out/
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.venv/**
.ruff_cache/**
out/
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "extensionHost",
"request": "launch",
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
"preLaunchTask": "Generate from templates"
"preLaunchTask": "PreLaunch Tasks"
}
]
}
18 changes: 16 additions & 2 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,22 @@
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
}
},
{
"label": "Compile TypeScript",
"type": "shell",
"command": "npm",
"args": ["run", "compile:ts"],
"group": {
"kind": "build",
"isDefault": false
}
},
{
"label": "PreLaunch Tasks",
"dependsOrder": "sequence",
"dependsOn": ["Generate from templates", "Compile TypeScript"]
}
]
}
1 change: 1 addition & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
node_modules/**
test/**
.gitignore
out/

utils/**
templates/**
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ This extension provides syntax highlighting support for MODFLOW 6 input files in

## Usage

- The extension activates based on the file's extension. If not detected, use `Change Language Mode` in VS Code and set it to `MODFLOW 6`.
- The extension activates based on the file's extension. If not detected, use `MF6 Syntax: Syntax-highlight as MF6 file` command to set MF6 as the language mode.
- VS Code's minimap can display enlarged section headers (block names), which may appear cluttered. To simplify the view, disable this feature by setting `editor.minimap.showRegionSectionHeaders` to `false`.
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,23 @@
},
"license": "MIT",
"publisher": "mart-clanor",
"main": "./out/extension.js",
"scripts": {
"check:prettier": "prettier --check .",
"compile:ts": "tsc -p ./",
"package": "vsce package",
"publish": "vsce publish",
"test:grammar": "vscode-tmgrammar-snap syntaxes/samples/*",
"update:snapshot": "vscode-tmgrammar-snap --updateSnapshot syntaxes/samples/*"
},
"contributes": {
"commands": [
{
"command": "mf6-syntax.mf6-ify",
"title": "Syntax-highlight as MF6 file",
"category": "MF6 Syntax"
}
],
"grammars": [
{
"language": "mf6",
Expand Down Expand Up @@ -144,8 +153,10 @@
]
},
"devDependencies": {
"@types/vscode": "^1.97.0",
"@vscode/vsce": "^3.2.2",
"prettier": "^3.5.0",
"typescript": "^5.7.3",
"vscode-tmgrammar-test": "^0.1.3"
},
"engines": {
Expand Down
16 changes: 16 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as vscode from "vscode";

export function activate(context: vscode.ExtensionContext) {
let disposable = vscode.commands.registerCommand("mf6-syntax.mf6-ify", () => {
if (vscode.window.activeTextEditor) {
vscode.languages.setTextDocumentLanguage(
vscode.window.activeTextEditor.document,
"mf6",
);
}
});

context.subscriptions.push(disposable);
}

export function deactivate() {}
11 changes: 11 additions & 0 deletions templates/package.json.j2
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,23 @@
},
"license": "MIT",
"publisher": "mart-clanor",
"main": "./out/extension.js",
"scripts": {
"check:prettier": "prettier --check .",
"compile:ts": "tsc -p ./",
"package": "vsce package",
"publish": "vsce publish",
"test:grammar": "vscode-tmgrammar-snap syntaxes/samples/*",
"update:snapshot": "vscode-tmgrammar-snap --updateSnapshot syntaxes/samples/*"
},
"contributes": {
"commands": [
{
"command": "mf6-syntax.mf6-ify",
"title": "Syntax-highlight as MF6 file",
"category": "MF6 Syntax"
}
],
"grammars": [
{
"language": "mf6",
Expand Down Expand Up @@ -60,8 +69,10 @@
]
},
"devDependencies": {
"@types/vscode": "^1.97.0",
"@vscode/vsce": "^3.2.2",
"prettier": "^3.5.0",
"typescript": "^5.7.3",
"vscode-tmgrammar-test": "^0.1.3"
},
"engines": {
Expand Down
12 changes: 12 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"outDir": "out",
"rootDir": "src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true
},
"include": ["src"]
}

0 comments on commit c52bcc9

Please sign in to comment.