mirror of
https://github.com/Strum355/mcshader-lsp.git
synced 2025-07-23 03:05:44 +00:00
More logging, more try catches, and updated README. 0.8.2 released!
This commit is contained in:
parent
2421aeb32c
commit
27334114e3
7 changed files with 88 additions and 52 deletions
|
@ -4,11 +4,11 @@ All notable changes to the "vscode-mc-shader" extension will be documented in th
|
||||||
|
|
||||||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
||||||
|
|
||||||
## [Unreleased]
|
## [0.8.2]
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Incomplete completion items
|
|
||||||
- Support for #include directives
|
- Support for #include directives
|
||||||
- Basic linting with highlighting.
|
- Basic linting with highlighting with error propogation to all known parents of an include.
|
||||||
- Support for .fsh, .vsh, .glsl and .gsh files.
|
- Support for .fsh, .vsh, .glsl and .gsh files.
|
||||||
|
- Incomplete completion items
|
35
README.md
35
README.md
|
@ -7,7 +7,7 @@
|
||||||
[](https://codeclimate.com/github/Strum355/vscode-mc-shader/maintainability)
|
[](https://codeclimate.com/github/Strum355/vscode-mc-shader/maintainability)
|
||||||
[](https://waffle.io/Strum355/vscode-mc-shader) -->
|
[](https://waffle.io/Strum355/vscode-mc-shader) -->
|
||||||
|
|
||||||
VSCode-MC-Shader is a [Visual Studio Code](https://code.visualstudio.com/) extension for developing Minecraft GLSL Shaders for [Optifine](http://optifine.net). It currently provides linting and syntax highlighting (by stef-levesque/vscode-shader dependency).
|
VSCode-mc-shader is a [Visual Studio Code](https://code.visualstudio.com/) extension for developing Minecraft GLSL Shaders for [Optifine](http://optifine.net). It currently provides linting and syntax highlighting (by stef-levesque/vscode-shader dependency).
|
||||||
|
|
||||||
<img src="https://github.com/Strum355/vscode-mc-shader/raw/master/logo.png" width="20%" height="20%">
|
<img src="https://github.com/Strum355/vscode-mc-shader/raw/master/logo.png" width="20%" height="20%">
|
||||||
|
|
||||||
|
@ -16,23 +16,22 @@ VSCode-MC-Shader is a [Visual Studio Code](https://code.visualstudio.com/) exten
|
||||||
- Linting
|
- Linting
|
||||||
- Syntax highlighting (by extension dependency)
|
- Syntax highlighting (by extension dependency)
|
||||||
- Support for `#include` directives
|
- Support for `#include` directives
|
||||||
- Auto-complete prompts (incomplete)
|
- Auto-complete prompts (incomplete and rough)
|
||||||
|
|
||||||
## Planned
|
## Installation (assumes installing from VSCode extension tab)
|
||||||
|
|
||||||
- Multi-workspaces (currently only one is supported and using multiple is very undefined behaviour)
|
- After reloading, open a shaderpack's folder.
|
||||||
- Warnings for unused uniforms/varyings
|
- You should be prompted to set your shaderpacks folder e.g. `"mcglsl.shaderpacksPath": "C:/Users/Noah/AppData/Roaming/.minecraft/shaderpacks"`
|
||||||
- Some cool `DRAWBUFFERS` stuff
|
- You should then be prompted saying `glslangValidator` isn't installed. Hit the download button and wait for a notification saying that it's been installed.
|
||||||
|
- You should now be good to go!
|
||||||
Got a feature request? Chuck it into an Issue!
|
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
- Visual Studio Code (v1.17.0 or higher - minimum requirement untested)
|
- Visual Studio Code (v1.23.0 or higher - minimum requirement untested).
|
||||||
- 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 [Shader languages support for VS Code](https://marketplace.visualstudio.com/items?itemName=slevesque.shader) extension. This should automatically install when you install this extension.
|
||||||
- That the shader(s) you're editing are in the `shaderpacks` folder in `.minecraft`.
|
- That the shader(s) you're editing are in the `shaderpacks` folder in `.minecraft`.
|
||||||
- The [OpenGL / OpenGL ES Reference Compiler](https://github.com/KhronosGroup/glslang) (for convenience, put it in your PATH, this is the assumed location if not specified). If, for some reason, you're using MacOS, there are no pre-compiled binaries of this.
|
- That you've only one shader folder open. Multiple workspaces aren't currently supported.
|
||||||
- [MacOS] Not MacOS. Not that you're making MC Shaders on/for MacOS anyways...right?
|
- The [OpenGL / OpenGL ES Reference Compiler](https://github.com/KhronosGroup/glslang). The extension will give you an option to download it and update your settings automatically.
|
||||||
|
|
||||||
## Extension Settings
|
## Extension Settings
|
||||||
|
|
||||||
|
@ -45,14 +44,22 @@ Got a feature request? Chuck it into an Issue!
|
||||||
|
|
||||||
Please see [CONTRIBUTING.md](https://github.com/Strum355/vscode-mc-shader/blob/master/CONTRIBUTING.md).
|
Please see [CONTRIBUTING.md](https://github.com/Strum355/vscode-mc-shader/blob/master/CONTRIBUTING.md).
|
||||||
|
|
||||||
|
## Planned
|
||||||
|
|
||||||
|
- Multi-workspaces (currently only one is supported and using multiple is very undefined behaviour)
|
||||||
|
- Warnings for unused uniforms/varyings
|
||||||
|
- Some cool `DRAWBUFFERS` stuff
|
||||||
|
|
||||||
|
Got a feature request? Chuck it into an Issue!
|
||||||
|
|
||||||
## Known Issues
|
## Known Issues
|
||||||
|
|
||||||
I'll fill this in once this actually gets released.
|
Check the issues on Github [here](https://github.com/Strum355/vscode-mc-shader/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3Abug).
|
||||||
|
|
||||||
## Release Notes
|
## Release Notes
|
||||||
|
|
||||||
None yet.
|
Check [CHANGELOG.md](https://github.com/Strum355/vscode-mc-shader/blob/master/CHANGELOG.md).
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
This code is released under the MIT License. Copyright (c) 2018 Noah Santschi-Cooney
|
This code is released under the [MIT License](https://github.com/Strum355/vscode-mc-shader/blob/master/LICENSE). Copyright (c) 2018 Noah Santschi-Cooney
|
||||||
|
|
6
client/package-lock.json
generated
6
client/package-lock.json
generated
|
@ -1619,9 +1619,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"url-parse": {
|
"url-parse": {
|
||||||
"version": "1.4.0",
|
"version": "1.4.3",
|
||||||
"resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.4.3.tgz",
|
||||||
"integrity": "sha512-ERuGxDiQ6Xw/agN4tuoCRbmwRuZP0cJ1lJxJubXr5Q/5cDa78+Dc4wfvtxzhzhkm5VvmW6Mf8EVj9SPGN4l8Lg==",
|
"integrity": "sha512-rh+KuAW36YKo0vClhQzLLveoj8FwPJNu65xLb7Mrt+eZht0IPT0IXgSv8gcMegZ6NvjJUALf6Mf25POlMwD1Fw==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"querystringify": "^2.0.0",
|
"querystringify": "^2.0.0",
|
||||||
"requires-port": "^1.0.0"
|
"requires-port": "^1.0.0"
|
||||||
|
|
2
package-lock.json
generated
2
package-lock.json
generated
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "vscode-mc-shader",
|
"name": "vscode-mc-shader",
|
||||||
"version": "0.0.1",
|
"version": "0.8.1",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"name": "vscode-mc-shader",
|
"name": "vscode-mc-shader",
|
||||||
"displayName": "Minecraft GLSL Shaders",
|
"displayName": "Minecraft GLSL Shaders",
|
||||||
"description": "A Visual Studio Code extension for linting/etc Minecraft GLSL Shaders",
|
"description": "A Visual Studio Code extension for linting/etc Minecraft GLSL Shaders",
|
||||||
"version": "0.8.1",
|
"version": "0.8.2",
|
||||||
"publisher": "Strum355",
|
"publisher": "Strum355",
|
||||||
"author": "Noah Santschi-Cooney (Strum355)",
|
"author": "Noah Santschi-Cooney (Strum355)",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
import { connection, documents, onEvent } from './server'
|
import { connection, documents, onEvent } from './server'
|
||||||
import fetch from 'node-fetch'
|
import fetch from 'node-fetch'
|
||||||
import { platform } from 'os'
|
import { platform } from 'os'
|
||||||
import { createWriteStream, chmodSync, createReadStream, unlinkSync, read } from 'fs'
|
import { createWriteStream, chmodSync, createReadStream, unlinkSync, read, WriteStream } from 'fs'
|
||||||
import * as unzip from 'unzip'
|
import * as unzip from 'unzip'
|
||||||
import { postError } from './utils'
|
import { postError } from './utils'
|
||||||
import { execSync } from 'child_process'
|
import { execSync } from 'child_process'
|
||||||
import { serverLog } from './logging'
|
import { serverLog } from './logging'
|
||||||
import { dirname } from 'path'
|
import { dirname } from 'path'
|
||||||
import { DidChangeConfigurationParams } from 'vscode-languageserver/lib/main'
|
import { DidChangeConfigurationParams } from 'vscode-languageserver'
|
||||||
import { win } from './linter';
|
import { win } from './linter'
|
||||||
|
|
||||||
const url = {
|
const url = {
|
||||||
'win32': 'https://github.com/KhronosGroup/glslang/releases/download/master-tot/glslang-master-windows-x64-Release.zip',
|
'win32': 'https://github.com/KhronosGroup/glslang/releases/download/master-tot/glslang-master-windows-x64-Release.zip',
|
||||||
|
@ -36,8 +36,10 @@ export async function onConfigChange(change: DidChangeConfigurationParams) {
|
||||||
|
|
||||||
if (conf.shaderpacksPath === '' || conf.shaderpacksPath.replace(dirname(conf.shaderpacksPath), '') !== '/shaderpacks') {
|
if (conf.shaderpacksPath === '' || conf.shaderpacksPath.replace(dirname(conf.shaderpacksPath), '') !== '/shaderpacks') {
|
||||||
if (supress) return
|
if (supress) return
|
||||||
|
|
||||||
serverLog.error(() => 'shaderpack path not set or doesn\'t end in \'shaderpacks\'', null)
|
serverLog.error(() => 'shaderpack path not set or doesn\'t end in \'shaderpacks\'', null)
|
||||||
supress = true
|
supress = true
|
||||||
|
|
||||||
const clicked = await connection.window.showErrorMessage(
|
const clicked = await connection.window.showErrorMessage(
|
||||||
'mcglsl.shaderpacksPath is not set or doesn\'t end in \'shaderpacks\'. Please set it in your settings.',
|
'mcglsl.shaderpacksPath is not set or doesn\'t end in \'shaderpacks\'. Please set it in your settings.',
|
||||||
{title: 'Supress'}
|
{title: 'Supress'}
|
||||||
|
@ -78,29 +80,47 @@ async function promptDownloadGlslang() {
|
||||||
async function downloadGlslang() {
|
async function downloadGlslang() {
|
||||||
connection.window.showInformationMessage('Downloading. Your settings will be updated automatically and you\'ll be notified when its done.')
|
connection.window.showInformationMessage('Downloading. Your settings will be updated automatically and you\'ll be notified when its done.')
|
||||||
|
|
||||||
|
serverLog.info(() => 'downloading glslangValidator...')
|
||||||
|
|
||||||
const res = await fetch(url[platform()])
|
const res = await fetch(url[platform()])
|
||||||
|
|
||||||
|
serverLog.info(() => 'glslangValidator downloaded. Extracting...')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const zip = createWriteStream(conf.shaderpacksPath + '/glslangValidator.zip')
|
const zip = createWriteStream(conf.shaderpacksPath + '/glslangValidator.zip')
|
||||||
res.body.pipe(zip)
|
res.body.pipe(zip)
|
||||||
|
|
||||||
|
const glslang = '/glslangValidator' + (win ? '.exe' : '')
|
||||||
|
|
||||||
zip.on('finish', async () => {
|
zip.on('finish', async () => {
|
||||||
createReadStream(conf.shaderpacksPath + '/glslangValidator.zip')
|
try {
|
||||||
.pipe(unzip.Parse())
|
createReadStream(conf.shaderpacksPath + '/glslangValidator.zip')
|
||||||
.on('entry', entry => {
|
.pipe(unzip.Parse())
|
||||||
if (entry.path === 'bin/glslangValidator' + win ? '.exe' : '') {
|
.on('entry', entry => {
|
||||||
entry.pipe(createWriteStream(conf.shaderpacksPath + '/glslangValidator' + win ? '.exe' : ''))
|
try {
|
||||||
return
|
if (entry.path === 'bin' + glslang) {
|
||||||
}
|
entry.pipe(createWriteStream(conf.shaderpacksPath + glslang))
|
||||||
entry.autodrain()
|
return
|
||||||
})
|
}
|
||||||
.on('close', () => {
|
entry.autodrain()
|
||||||
chmodSync(conf.shaderpacksPath + '/glslangValidator' + win ? '.exe' : '', 0o775)
|
} catch (e) {
|
||||||
unlinkSync(conf.shaderpacksPath + '/glslangValidator.zip')
|
postError(e)
|
||||||
connection.sendNotification('update-config', conf.shaderpacksPath + '/glslangValidator' + win ? '.exe' : '')
|
}
|
||||||
connection.window.showInformationMessage('glslangValidator has been downloaded to ' + conf.shaderpacksPath + '/glslangValidator. Your config should be updated automatically.')
|
})
|
||||||
glslangReady = true
|
.on('close', () => {
|
||||||
})
|
try {
|
||||||
|
chmodSync(conf.shaderpacksPath + glslang, 0o775)
|
||||||
|
unlinkSync(conf.shaderpacksPath + '/glslangValidator.zip')
|
||||||
|
connection.sendNotification('update-config', conf.shaderpacksPath + glslang)
|
||||||
|
connection.window.showInformationMessage('glslangValidator has been downloaded to ' + conf.shaderpacksPath + '/glslangValidator. Your config should be updated automatically.')
|
||||||
|
glslangReady = true
|
||||||
|
} catch (e) {
|
||||||
|
postError(e)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} catch (e) {
|
||||||
|
postError(e)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
postError(e)
|
postError(e)
|
||||||
|
|
|
@ -82,19 +82,18 @@ const tokens = new Map([
|
||||||
])
|
])
|
||||||
|
|
||||||
export function preprocess(lines: string[], docURI: string) {
|
export function preprocess(lines: string[], docURI: string) {
|
||||||
const hasDirective = includeDirective(lines, docURI)
|
const hasDirective = includeDirective(lines)
|
||||||
|
|
||||||
const allIncludes = new Set<IncludeObj>()
|
|
||||||
const diagnostics = new Map<string, Diagnostic[]>()
|
const diagnostics = new Map<string, Diagnostic[]>()
|
||||||
|
|
||||||
processIncludes(lines, [docURI], allIncludes, diagnostics, hasDirective)
|
processIncludes(lines, [docURI], new Set<IncludeObj>(), diagnostics, hasDirective)
|
||||||
|
|
||||||
const includeMap = new Map<string, IncludeObj>(Array.from(allIncludes).map(obj => [obj.path, obj]) as [string, IncludeObj][])
|
//const includeMap = new Map<string, IncludeObj>(Array.from(allIncludes).map(obj => [obj.path, obj]) as [string, IncludeObj][])
|
||||||
|
|
||||||
lint(docURI, lines, includeMap, diagnostics, hasDirective)
|
lint(docURI, lines, diagnostics, hasDirective)
|
||||||
}
|
}
|
||||||
|
|
||||||
function includeDirective(lines: string[], docURI: string): boolean {
|
function includeDirective(lines: string[]): boolean {
|
||||||
if (lines.findIndex(x => reIncludeExt.test(x)) > -1) {
|
if (lines.findIndex(x => reIncludeExt.test(x)) > -1) {
|
||||||
linterLog.info(() => 'include directive found')
|
linterLog.info(() => 'include directive found')
|
||||||
return true
|
return true
|
||||||
|
@ -259,7 +258,7 @@ function mergeInclude(inc: IncludeObj, lines: string[], incStack: string[], diag
|
||||||
lines.splice(inc.lineNumTopLevel + 1 + dataLines.length, 0, `#line ${inc.lineNum + 1} "${inc.parent}"`)
|
lines.splice(inc.lineNumTopLevel + 1 + dataLines.length, 0, `#line ${inc.lineNum + 1} "${inc.parent}"`)
|
||||||
}
|
}
|
||||||
|
|
||||||
function lint(docURI: string, lines: string[], includes: Map<string, IncludeObj>, diagnostics: Map<string, Diagnostic[]>, hasDirective: boolean) {
|
function lint(docURI: string, lines: string[], diagnostics: Map<string, Diagnostic[]>, hasDirective: boolean) {
|
||||||
let out: string = ''
|
let out: string = ''
|
||||||
try {
|
try {
|
||||||
execSync(`${conf.glslangPath} --stdin -S ${ext.get(path.extname(docURI))}`, {input: lines.join('\n')})
|
execSync(`${conf.glslangPath} --stdin -S ${ext.get(path.extname(docURI))}`, {input: lines.join('\n')})
|
||||||
|
@ -274,7 +273,16 @@ function lint(docURI: string, lines: string[], includes: Map<string, IncludeObj>
|
||||||
|
|
||||||
processErrors(out, docURI, diagnostics, hasDirective)
|
processErrors(out, docURI, diagnostics, hasDirective)
|
||||||
|
|
||||||
daigsArray(diagnostics).forEach(d => {
|
diagnostics.forEach((diags, uri) => {
|
||||||
|
if (diags.length === 0) return
|
||||||
|
linterLog.info(() => `found ${diags.length} error(s) for ${trimPath(uri)}`)
|
||||||
|
})
|
||||||
|
|
||||||
|
const diagsList = daigsArray(diagnostics)
|
||||||
|
|
||||||
|
if (diagsList.filter(d => d.diag.length > 0).length === 0) linterLog.info(() => 'no errors found')
|
||||||
|
|
||||||
|
diagsList.forEach(d => {
|
||||||
if (win) d.uri = d.uri.replace('file://C:', 'file:///c%3A')
|
if (win) d.uri = d.uri.replace('file://C:', 'file:///c%3A')
|
||||||
connection.sendDiagnostics({uri: d.uri, diagnostics: d.diag})
|
connection.sendDiagnostics({uri: d.uri, diagnostics: d.diag})
|
||||||
})
|
})
|
||||||
|
@ -293,7 +301,8 @@ function processErrors(out: string, docURI: string, diagnostics: Map<string, Dia
|
||||||
|
|
||||||
const diag: Diagnostic = {
|
const diag: Diagnostic = {
|
||||||
severity: error.type,
|
severity: error.type,
|
||||||
range: calcRange(error.line - ((!hasDirective && includeGraph.get(fileName).parents.size === 0) ? 2 : 1), fileName),
|
range: calcRange(error.line - 1, fileName),
|
||||||
|
//range: calcRange(error.line - ((!hasDirective && includeGraph.get(fileName).parents.size === 0) ? 2 : 1), fileName),
|
||||||
message: `Line ${error.line + 1} ${replaceWords(error.msg)}`,
|
message: `Line ${error.line + 1} ${replaceWords(error.msg)}`,
|
||||||
source: 'mc-glsl'
|
source: 'mc-glsl'
|
||||||
}
|
}
|
||||||
|
@ -337,7 +346,7 @@ const filterMatches = (output: string) => output
|
||||||
.filter(match => match && match.length === 5)
|
.filter(match => match && match.length === 5)
|
||||||
|
|
||||||
function calcRange(lineNum: number, uri: string): Range {
|
function calcRange(lineNum: number, uri: string): Range {
|
||||||
linterLog.debug(() => `calculating range for ${trimPath(uri)} at L${lineNum}`)
|
linterLog.debug(() => `calculating range for ${trimPath(uri)} at L${lineNum + 1}`)
|
||||||
|
|
||||||
const lines = getDocumentContents(uri).split('\n')
|
const lines = getDocumentContents(uri).split('\n')
|
||||||
const line = lines[lineNum]
|
const line = lines[lineNum]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue