mirror of
https://github.com/Strum355/mcshader-lsp.git
synced 2025-08-04 00:49:17 +00:00
Guess we should make this pro-fesh-ional. tslint doesnt seem to like the config file tho :(
This commit is contained in:
parent
5b8fe6cf09
commit
188ad2a419
5 changed files with 51 additions and 56 deletions
|
@ -1,7 +1,11 @@
|
|||
# Change Log
|
||||
|
||||
All notable changes to the "vscode-mc-shader" extension will be documented in this file.
|
||||
|
||||
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
||||
|
||||
## [Unreleased]
|
||||
- Initial release
|
||||
|
||||
### Added
|
||||
- Basic linting with highlighting.
|
||||
- Support for .fsh, .vsh and .gsh files
|
25
README.md
25
README.md
|
@ -1,27 +1,36 @@
|
|||
# vscode-mc-shader
|
||||
|
||||
This is an extension for [Visual Studio Code](https://code.visualstudio.com/). It (will) provide linting, syntax highlighting, warnings for unused uniforms, some cool DRAWBUFFERS stuff, auto-complete options and whatever else I think of for developing Minecraft GLSL Shaders using [Optifine](http://optifine.net).
|
||||
This is an extension for [Visual Studio Code](https://code.visualstudio.com/) for developing Minecraft GLSL Shaders for [Optifine](http://optifine.net). It currently provides linting and syntax highlighting (by stef-levesque/vscode-shader dependency).
|
||||
|
||||
## Features
|
||||
|
||||
So far? Nothing
|
||||
- Linting (unpolished)
|
||||
- Syntax highlighting (by extension dependency)
|
||||
|
||||
## Planned
|
||||
|
||||
- Support for `#includes`
|
||||
- Warnings for unused uniforms/varyings
|
||||
- Some cool `DRAWBUFFERS` stuff
|
||||
- Auto-complete prompts
|
||||
|
||||
Got a feature request? Chuck it into an Issue!
|
||||
|
||||
## Requirements
|
||||
|
||||
- Visual Studio Code of course
|
||||
- The [Shader languages support for VS Code](https://marketplace.visualstudio.com/items?itemName=slevesque.shader) extension
|
||||
- Not MacOSX. Not that you're making MC Shaders on/for MacOSX anyways...right?
|
||||
- The [Shader languages support for VS Code](https://marketplace.visualstudio.com/items?itemName=slevesque.shader) extension. This should automatically install when you install this extension
|
||||
- The [OpenGL / OpenGL ES Reference Compiler](https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang/Install/) (for convenience, put it in your PATH)
|
||||
|
||||
## Extension Settings
|
||||
|
||||
- `mcglsl.glslangValidatorPath` : The path to the glslangValidator executable
|
||||
- `mcglsl.glslangValidatorPath` : The path to the glslangValidator executable. If not provided, it assumes its in your `PATH`.
|
||||
|
||||
## Known Issues
|
||||
|
||||
It doesn't work yet I guess...
|
||||
I'll fill this in once this actually gets released.
|
||||
|
||||
## Release Notes
|
||||
|
||||
### X.X.X
|
||||
|
||||
I added code. It does nothing really.
|
||||
None yet.
|
||||
|
|
|
@ -7,11 +7,14 @@ import * as fs from 'fs'
|
|||
import * as shell from 'shelljs'
|
||||
import * as path from 'path'
|
||||
|
||||
interface config {
|
||||
// glslangPath: Path to glslangValidator (assumed in PATH by default)
|
||||
// tmpdir: the directory into which the symlinks are stored, should be the OS's temp dir
|
||||
interface Config {
|
||||
glslangPath: string
|
||||
tmpdir: string
|
||||
}
|
||||
|
||||
// These are used for symlinking as glslangValidator only accepts files in these formats
|
||||
const extensions: { [id: string] : string } = {
|
||||
'.fsh': '.frag',
|
||||
'.vsh': '.vert',
|
||||
|
@ -19,13 +22,15 @@ const extensions: { [id: string] : string } = {
|
|||
'.glsl': '.frag'
|
||||
}
|
||||
|
||||
// These will be used to filter out error messages that are irrelevant/incorrect for us
|
||||
// Lot of testing needed to find all the ones that we need to match
|
||||
const filters: RegExp[] = [
|
||||
/(not supported for this version or the enabled extensions)/g
|
||||
]
|
||||
|
||||
export default class GLSLProvider implements vscode.CodeActionProvider {
|
||||
private diagnosticCollection: vscode.DiagnosticCollection
|
||||
private config: config
|
||||
private diagnosticCollection: vscode.DiagnosticCollection // where errors/warnings/hints are pushed to be displayed
|
||||
private config: Config
|
||||
|
||||
constructor(subs: vscode.Disposable[]) {
|
||||
this.diagnosticCollection = vscode.languages.createDiagnosticCollection()
|
||||
|
@ -39,7 +44,7 @@ export default class GLSLProvider implements vscode.CodeActionProvider {
|
|||
console.log('[MC-GLSL] Successfully made temp directory', `${this.config.tmpdir}`)
|
||||
} catch(e) {
|
||||
console.error('[MC-GLSL] Error creating temp dir', e)
|
||||
vscode.window.showErrorMessage('[MC-GLSL] Error creat ing temp directory. Check developer tools for more info.')
|
||||
vscode.window.showErrorMessage('[MC-GLSL] Error creating temp directory. Check developer tools for more info.')
|
||||
}
|
||||
|
||||
vscode.workspace.onDidOpenTextDocument(this.lint, this)
|
||||
|
@ -54,18 +59,19 @@ export default class GLSLProvider implements vscode.CodeActionProvider {
|
|||
})
|
||||
}
|
||||
|
||||
private initConfig(): config {
|
||||
private initConfig(): Config {
|
||||
const c = vscode.workspace.getConfiguration('mcglsl')
|
||||
|
||||
console.log('[MC-GLSL] glslangValidatorPath set to', c.get('glslangValidatorPath'))
|
||||
console.log('[MC-GLSL] temp directory root set to', path.join(os.tmpdir(), vscode.workspace.name!!, 'shaders'))
|
||||
console.log('[MC-GLSL] temp directory root set to', path.join(os.tmpdir(), vscode.workspace.name!, 'shaders'))
|
||||
|
||||
return {
|
||||
glslangPath: c.get('glslangValidatorPath') as string,
|
||||
tmpdir: path.join(os.tmpdir(), vscode.workspace.name!!, 'shaders')
|
||||
tmpdir: path.join(os.tmpdir(), vscode.workspace.name!, 'shaders')
|
||||
}
|
||||
}
|
||||
|
||||
// Called when the config files are changed
|
||||
private configChange(e: vscode.ConfigurationChangeEvent) {
|
||||
if (e.affectsConfiguration('mcglsl')) {
|
||||
console.log('[MC-GLSL] config changed')
|
||||
|
@ -74,6 +80,7 @@ export default class GLSLProvider implements vscode.CodeActionProvider {
|
|||
}
|
||||
}
|
||||
|
||||
// Check if glslangValidator binary can be found
|
||||
private checkBinary() {
|
||||
let ret = shell.which(this.config.glslangPath)
|
||||
|
||||
|
@ -83,6 +90,7 @@ export default class GLSLProvider implements vscode.CodeActionProvider {
|
|||
' Use the config option "mcglsl.glslangValidatorPath" to point to its location'
|
||||
)
|
||||
} else {
|
||||
// Do we want this here? ¯\_(ツ)_/¯
|
||||
vscode.window.showInformationMessage('[MC-GLSL] glslangValidator found!')
|
||||
}
|
||||
}
|
||||
|
@ -92,19 +100,22 @@ export default class GLSLProvider implements vscode.CodeActionProvider {
|
|||
this.diagnosticCollection.dispose()
|
||||
}
|
||||
|
||||
// Maybe only lint when files are saved...hmmm
|
||||
private docChange(e: vscode.TextDocumentChangeEvent) {
|
||||
this.lint(e.document)
|
||||
}
|
||||
|
||||
// This doesnt work yet >:( note: use .test instead of .match
|
||||
private matchesFilters(s: string): boolean {
|
||||
return filters.some((reg: RegExp, i: number, array: RegExp[]) => {
|
||||
let m = s.match(reg)
|
||||
console.log(s)
|
||||
console.log(m)
|
||||
return (m && m.length > 1)!!
|
||||
return (m && m.length > 1)!
|
||||
})
|
||||
}
|
||||
|
||||
// The big boi that does all the shtuff
|
||||
private lint(document: vscode.TextDocument) {
|
||||
if(document.languageId !== 'glsl') {
|
||||
return
|
||||
|
@ -124,6 +135,7 @@ export default class GLSLProvider implements vscode.CodeActionProvider {
|
|||
//.filter((s: string) => { return !this.matchesFilters(s)} )
|
||||
|
||||
if (lines.length < 1) {
|
||||
// If there were no errors, we need to set the list empty so that the editor reflects that
|
||||
this.diagnosticCollection.set(document.uri, [])
|
||||
return
|
||||
}
|
||||
|
@ -131,14 +143,14 @@ export default class GLSLProvider implements vscode.CodeActionProvider {
|
|||
let diags: vscode.Diagnostic[] = []
|
||||
|
||||
lines.forEach((line: string) => {
|
||||
// Default to error
|
||||
let matches = line.match(/WARNING:|ERROR:\s\d+:(\d+): (\W.*)/)
|
||||
if (!matches || (matches && matches.length < 3)) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
let [lineNum, message] = matches.slice(1,3)
|
||||
|
||||
|
||||
// Default to error
|
||||
let severity: vscode.DiagnosticSeverity = vscode.DiagnosticSeverity.Error
|
||||
if(!line.startsWith('ERROR:')) {
|
||||
// for now assume theres either errors or warnings. Maybe thats even the case!
|
||||
|
|
|
@ -4,11 +4,14 @@
|
|||
"no-unused-expression": true,
|
||||
"no-duplicate-variable": true,
|
||||
"curly": true,
|
||||
"prefer-for-of": true,
|
||||
"no-duplicate-switch-case": true,
|
||||
"no-shadowed-variable": true,
|
||||
"no-use-before-declare": true,
|
||||
"class-name": true,
|
||||
"semicolon": [
|
||||
false,
|
||||
false
|
||||
],
|
||||
"triple-equals": true
|
||||
},
|
||||
"defaultSeverity": "warning"
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
# 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`.
|
||||
|
||||
## 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/vscode/vscode.d.ts`.
|
||||
|
||||
## Run tests
|
||||
* Open the debug viewlet (`Ctrl+Shift+D` or `Cmd+Shift+D` on Mac) and from the launch configuration dropdown pick `Launch Tests`.
|
||||
* Press `F5` to run the tests in a new window with your extension loaded.
|
||||
* See the output of the test result in the debug console.
|
||||
* Make changes to `test/extension.test.ts` or create new test files inside the `test` folder.
|
||||
* By convention, the 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.
|
Loading…
Add table
Add a link
Reference in a new issue