Skip to content

Commit 2733411

Browse files
committed
More logging, more try catches, and updated README. 0.8.2 released!
1 parent 2421aeb commit 2733411

File tree

7 files changed

+88
-52
lines changed

7 files changed

+88
-52
lines changed

CHANGELOG.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ All notable changes to the "vscode-mc-shader" extension will be documented in th
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66

7-
## [Unreleased]
7+
## [0.8.2]
88

99
### Added
1010

11-
- Incomplete completion items
1211
- Support for #include directives
13-
- Basic linting with highlighting.
14-
- Support for .fsh, .vsh, .glsl and .gsh files.
12+
- Basic linting with highlighting with error propogation to all known parents of an include.
13+
- Support for .fsh, .vsh, .glsl and .gsh files.
14+
- Incomplete completion items

README.md

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[![Maintainability](https://api.codeclimate.com/v1/badges/c2c813cb0a42a8aad483/maintainability)](https://codeclimate.com/github/Strum355/vscode-mc-shader/maintainability)
88
[![Waffle.io - Columns and their card count](https://badge.waffle.io/Strum355/vscode-mc-shader.svg?columns=all)](https://waffle.io/Strum355/vscode-mc-shader) -->
99

10-
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).
10+
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).
1111

1212
<img src="https://github.com/Strum355/vscode-mc-shader/raw/master/logo.png" width="20%" height="20%">
1313

@@ -16,23 +16,22 @@ VSCode-MC-Shader is a [Visual Studio Code](https://code.visualstudio.com/) exten
1616
- Linting
1717
- Syntax highlighting (by extension dependency)
1818
- Support for `#include` directives
19-
- Auto-complete prompts (incomplete)
19+
- Auto-complete prompts (incomplete and rough)
2020

21-
## Planned
21+
## Installation (assumes installing from VSCode extension tab)
2222

23-
- Multi-workspaces (currently only one is supported and using multiple is very undefined behaviour)
24-
- Warnings for unused uniforms/varyings
25-
- Some cool `DRAWBUFFERS` stuff
26-
27-
Got a feature request? Chuck it into an Issue!
23+
- After reloading, open a shaderpack's folder.
24+
- You should be prompted to set your shaderpacks folder e.g. `"mcglsl.shaderpacksPath": "C:/Users/Noah/AppData/Roaming/.minecraft/shaderpacks"`
25+
- 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.
26+
- You should now be good to go!
2827

2928
## Requirements
3029

31-
- Visual Studio Code (v1.17.0 or higher - minimum requirement untested)
30+
- Visual Studio Code (v1.23.0 or higher - minimum requirement untested).
3231
- 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.
3332
- That the shader(s) you're editing are in the `shaderpacks` folder in `.minecraft`.
34-
- 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.
35-
- [MacOS] Not MacOS. Not that you're making MC Shaders on/for MacOS anyways...right?
33+
- That you've only one shader folder open. Multiple workspaces aren't currently supported.
34+
- 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.
3635

3736
## Extension Settings
3837

@@ -45,14 +44,22 @@ Got a feature request? Chuck it into an Issue!
4544

4645
Please see [CONTRIBUTING.md](https://github.com/Strum355/vscode-mc-shader/blob/master/CONTRIBUTING.md).
4746

47+
## Planned
48+
49+
- Multi-workspaces (currently only one is supported and using multiple is very undefined behaviour)
50+
- Warnings for unused uniforms/varyings
51+
- Some cool `DRAWBUFFERS` stuff
52+
53+
Got a feature request? Chuck it into an Issue!
54+
4855
## Known Issues
4956

50-
I'll fill this in once this actually gets released.
57+
Check the issues on Github [here](https://github.com/Strum355/vscode-mc-shader/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3Abug).
5158

5259
## Release Notes
5360

54-
None yet.
61+
Check [CHANGELOG.md](https://github.com/Strum355/vscode-mc-shader/blob/master/CHANGELOG.md).
5562

5663
## License
5764

58-
This code is released under the MIT License. Copyright (c) 2018 Noah Santschi-Cooney
65+
This code is released under the [MIT License](https://github.com/Strum355/vscode-mc-shader/blob/master/LICENSE). Copyright (c) 2018 Noah Santschi-Cooney

client/package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-mc-shader",
33
"displayName": "Minecraft GLSL Shaders",
44
"description": "A Visual Studio Code extension for linting/etc Minecraft GLSL Shaders",
5-
"version": "0.8.1",
5+
"version": "0.8.2",
66
"publisher": "Strum355",
77
"author": "Noah Santschi-Cooney (Strum355)",
88
"license": "MIT",

server/src/config.ts

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { connection, documents, onEvent } from './server'
22
import fetch from 'node-fetch'
33
import { platform } from 'os'
4-
import { createWriteStream, chmodSync, createReadStream, unlinkSync, read } from 'fs'
4+
import { createWriteStream, chmodSync, createReadStream, unlinkSync, read, WriteStream } from 'fs'
55
import * as unzip from 'unzip'
66
import { postError } from './utils'
77
import { execSync } from 'child_process'
88
import { serverLog } from './logging'
99
import { dirname } from 'path'
10-
import { DidChangeConfigurationParams } from 'vscode-languageserver/lib/main'
11-
import { win } from './linter';
10+
import { DidChangeConfigurationParams } from 'vscode-languageserver'
11+
import { win } from './linter'
1212

1313
const url = {
1414
'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) {
3636

3737
if (conf.shaderpacksPath === '' || conf.shaderpacksPath.replace(dirname(conf.shaderpacksPath), '') !== '/shaderpacks') {
3838
if (supress) return
39+
3940
serverLog.error(() => 'shaderpack path not set or doesn\'t end in \'shaderpacks\'', null)
4041
supress = true
42+
4143
const clicked = await connection.window.showErrorMessage(
4244
'mcglsl.shaderpacksPath is not set or doesn\'t end in \'shaderpacks\'. Please set it in your settings.',
4345
{title: 'Supress'}
@@ -78,29 +80,47 @@ async function promptDownloadGlslang() {
7880
async function downloadGlslang() {
7981
connection.window.showInformationMessage('Downloading. Your settings will be updated automatically and you\'ll be notified when its done.')
8082

83+
serverLog.info(() => 'downloading glslangValidator...')
84+
8185
const res = await fetch(url[platform()])
8286

87+
serverLog.info(() => 'glslangValidator downloaded. Extracting...')
88+
8389
try {
8490
const zip = createWriteStream(conf.shaderpacksPath + '/glslangValidator.zip')
8591
res.body.pipe(zip)
8692

93+
const glslang = '/glslangValidator' + (win ? '.exe' : '')
94+
8795
zip.on('finish', async () => {
88-
createReadStream(conf.shaderpacksPath + '/glslangValidator.zip')
89-
.pipe(unzip.Parse())
90-
.on('entry', entry => {
91-
if (entry.path === 'bin/glslangValidator' + win ? '.exe' : '') {
92-
entry.pipe(createWriteStream(conf.shaderpacksPath + '/glslangValidator' + win ? '.exe' : ''))
93-
return
94-
}
95-
entry.autodrain()
96-
})
97-
.on('close', () => {
98-
chmodSync(conf.shaderpacksPath + '/glslangValidator' + win ? '.exe' : '', 0o775)
99-
unlinkSync(conf.shaderpacksPath + '/glslangValidator.zip')
100-
connection.sendNotification('update-config', conf.shaderpacksPath + '/glslangValidator' + win ? '.exe' : '')
101-
connection.window.showInformationMessage('glslangValidator has been downloaded to ' + conf.shaderpacksPath + '/glslangValidator. Your config should be updated automatically.')
102-
glslangReady = true
103-
})
96+
try {
97+
createReadStream(conf.shaderpacksPath + '/glslangValidator.zip')
98+
.pipe(unzip.Parse())
99+
.on('entry', entry => {
100+
try {
101+
if (entry.path === 'bin' + glslang) {
102+
entry.pipe(createWriteStream(conf.shaderpacksPath + glslang))
103+
return
104+
}
105+
entry.autodrain()
106+
} catch (e) {
107+
postError(e)
108+
}
109+
})
110+
.on('close', () => {
111+
try {
112+
chmodSync(conf.shaderpacksPath + glslang, 0o775)
113+
unlinkSync(conf.shaderpacksPath + '/glslangValidator.zip')
114+
connection.sendNotification('update-config', conf.shaderpacksPath + glslang)
115+
connection.window.showInformationMessage('glslangValidator has been downloaded to ' + conf.shaderpacksPath + '/glslangValidator. Your config should be updated automatically.')
116+
glslangReady = true
117+
} catch (e) {
118+
postError(e)
119+
}
120+
})
121+
} catch (e) {
122+
postError(e)
123+
}
104124
})
105125
} catch (e) {
106126
postError(e)

server/src/linter.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,18 @@ const tokens = new Map([
8282
])
8383

8484
export function preprocess(lines: string[], docURI: string) {
85-
const hasDirective = includeDirective(lines, docURI)
85+
const hasDirective = includeDirective(lines)
8686

87-
const allIncludes = new Set<IncludeObj>()
8887
const diagnostics = new Map<string, Diagnostic[]>()
8988

90-
processIncludes(lines, [docURI], allIncludes, diagnostics, hasDirective)
89+
processIncludes(lines, [docURI], new Set<IncludeObj>(), diagnostics, hasDirective)
9190

92-
const includeMap = new Map<string, IncludeObj>(Array.from(allIncludes).map(obj => [obj.path, obj]) as [string, IncludeObj][])
91+
//const includeMap = new Map<string, IncludeObj>(Array.from(allIncludes).map(obj => [obj.path, obj]) as [string, IncludeObj][])
9392

94-
lint(docURI, lines, includeMap, diagnostics, hasDirective)
93+
lint(docURI, lines, diagnostics, hasDirective)
9594
}
9695

97-
function includeDirective(lines: string[], docURI: string): boolean {
96+
function includeDirective(lines: string[]): boolean {
9897
if (lines.findIndex(x => reIncludeExt.test(x)) > -1) {
9998
linterLog.info(() => 'include directive found')
10099
return true
@@ -259,7 +258,7 @@ function mergeInclude(inc: IncludeObj, lines: string[], incStack: string[], diag
259258
lines.splice(inc.lineNumTopLevel + 1 + dataLines.length, 0, `#line ${inc.lineNum + 1} "${inc.parent}"`)
260259
}
261260

262-
function lint(docURI: string, lines: string[], includes: Map<string, IncludeObj>, diagnostics: Map<string, Diagnostic[]>, hasDirective: boolean) {
261+
function lint(docURI: string, lines: string[], diagnostics: Map<string, Diagnostic[]>, hasDirective: boolean) {
263262
let out: string = ''
264263
try {
265264
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>
274273

275274
processErrors(out, docURI, diagnostics, hasDirective)
276275

277-
daigsArray(diagnostics).forEach(d => {
276+
diagnostics.forEach((diags, uri) => {
277+
if (diags.length === 0) return
278+
linterLog.info(() => `found ${diags.length} error(s) for ${trimPath(uri)}`)
279+
})
280+
281+
const diagsList = daigsArray(diagnostics)
282+
283+
if (diagsList.filter(d => d.diag.length > 0).length === 0) linterLog.info(() => 'no errors found')
284+
285+
diagsList.forEach(d => {
278286
if (win) d.uri = d.uri.replace('file://C:', 'file:///c%3A')
279287
connection.sendDiagnostics({uri: d.uri, diagnostics: d.diag})
280288
})
@@ -293,7 +301,8 @@ function processErrors(out: string, docURI: string, diagnostics: Map<string, Dia
293301

294302
const diag: Diagnostic = {
295303
severity: error.type,
296-
range: calcRange(error.line - ((!hasDirective && includeGraph.get(fileName).parents.size === 0) ? 2 : 1), fileName),
304+
range: calcRange(error.line - 1, fileName),
305+
//range: calcRange(error.line - ((!hasDirective && includeGraph.get(fileName).parents.size === 0) ? 2 : 1), fileName),
297306
message: `Line ${error.line + 1} ${replaceWords(error.msg)}`,
298307
source: 'mc-glsl'
299308
}
@@ -337,7 +346,7 @@ const filterMatches = (output: string) => output
337346
.filter(match => match && match.length === 5)
338347

339348
function calcRange(lineNum: number, uri: string): Range {
340-
linterLog.debug(() => `calculating range for ${trimPath(uri)} at L${lineNum}`)
349+
linterLog.debug(() => `calculating range for ${trimPath(uri)} at L${lineNum + 1}`)
341350

342351
const lines = getDocumentContents(uri).split('\n')
343352
const line = lines[lineNum]

0 commit comments

Comments
 (0)