Skip to content

Commit c3acbcb

Browse files
committed
Merged
2 parents 34b1377 + ced6e27 commit c3acbcb

File tree

5 files changed

+110
-55
lines changed

5 files changed

+110
-55
lines changed

CHANGELOG.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,23 @@ 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.4]
8+
9+
### Fixed
10+
11+
- Filtering out `global const initializers must be constant`. "Something something non-standard shader extensions that GPU developers implicitly enable" - Dethraid
12+
13+
## [0.8.3]
14+
15+
### Fixed
16+
17+
- Filtering out gpu_shader4 in code
18+
19+
## [0.8.2]
820

921
### Added
1022

11-
- Incomplete completion items
1223
- Support for #include directives
13-
- Basic linting with highlighting.
14-
- Support for .fsh, .vsh, .glsl and .gsh files.
24+
- Basic linting with highlighting with error propogation to all known parents of an include.
25+
- Support for .fsh, .vsh, .glsl and .gsh files.
26+
- 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

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.4",
66
"publisher": "Strum355",
77
"author": "Noah Santschi-Cooney (Strum355)",
88
"license": "MIT",

server/src/config.ts

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ 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'
10+
import { DidChangeConfigurationParams } from 'vscode-languageserver'
1111
import { win } from './linter'
1212

1313
const url = {
@@ -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', () => {
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: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { Diagnostic, DiagnosticSeverity, Range } from 'vscode-languageserver'
2-
import { connection, documents } from './server'
2+
import { connection } from './server'
33
import { execSync } from 'child_process'
44
import * as path from 'path'
5-
import { readFileSync, existsSync, statSync, Stats } from 'fs'
5+
import { readFileSync, statSync } from 'fs'
66
import { conf } from './config'
7-
import { postError, formatURI, getDocumentContents, trimPath } from './utils'
7+
import { formatURI, getDocumentContents, trimPath } from './utils'
88
import { platform } from 'os'
9-
import { Graph, Node } from './graph'
9+
import { Graph } from './graph'
1010
import { Comment } from './comment'
1111
import { linterLog } from './logging'
1212

@@ -17,11 +17,16 @@ const reIncludeExt = /#extension GL_GOOGLE_include_directive ?: ?require/
1717
const include = '#extension GL_GOOGLE_include_directive : require'
1818
export const win = platform() === 'win32'
1919

20-
const filters = [
20+
const errorFilters = [
2121
/stdin/,
2222
/(No code generated)/,
2323
/(compilation terminated)/,
24-
/Could not process include directive for header name:/
24+
/Could not process include directive for header name:/,
25+
/global const initializers must be constant/,
26+
]
27+
28+
const codeFilters = [
29+
/#extension GL_EXT_gpu_shader4 : require/,
2530
]
2631

2732
export const includeGraph = new Graph()
@@ -82,19 +87,18 @@ const tokens = new Map([
8287
])
8388

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

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

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

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

94-
lint(docURI, lines, includeMap, diagnostics, hasDirective)
98+
lint(docURI, lines, diagnostics, hasDirective)
9599
}
96100

97-
function includeDirective(lines: string[], docURI: string): boolean {
101+
function includeDirective(lines: string[]): boolean {
98102
if (lines.findIndex(x => reIncludeExt.test(x)) > -1) {
99103
linterLog.info(() => 'include directive found')
100104
return true
@@ -256,10 +260,12 @@ function mergeInclude(inc: IncludeObj, lines: string[], incStack: string[], diag
256260
// merge the lines of the file into the current document
257261
lines.splice(inc.lineNumTopLevel + 1, 0, ...dataLines)
258262
// add the closing #line indicating we're re-entering a block a level up
259-
lines.splice(inc.lineNumTopLevel + 1 + dataLines.length, 0, `#line ${inc.lineNum + 1} "${inc.parent}"`)
263+
lines.splice(inc.lineNumTopLevel + 1 + dataLines.length, 0, `#line ${inc.lineNum} "${inc.parent}"`)
260264
}
261265

262-
function lint(docURI: string, lines: string[], includes: Map<string, IncludeObj>, diagnostics: Map<string, Diagnostic[]>, hasDirective: boolean) {
266+
function lint(docURI: string, lines: string[], diagnostics: Map<string, Diagnostic[]>, hasDirective: boolean) {
267+
lines.forEach((l, i) => {if (codeFilters.some(r => r.test(l))) lines[i] = ''})
268+
263269
let out: string = ''
264270
try {
265271
execSync(`${conf.glslangPath} --stdin -S ${ext.get(path.extname(docURI))}`, {input: lines.join('\n')})
@@ -274,7 +280,16 @@ function lint(docURI: string, lines: string[], includes: Map<string, IncludeObj>
274280

275281
processErrors(out, docURI, diagnostics, hasDirective)
276282

277-
daigsArray(diagnostics).forEach(d => {
283+
diagnostics.forEach((diags, uri) => {
284+
if (diags.length === 0) return
285+
linterLog.info(() => `found ${diags.length} error(s) for ${trimPath(uri)}`)
286+
})
287+
288+
const diagsList = daigsArray(diagnostics)
289+
290+
if (diagsList.filter(d => d.diag.length > 0).length === 0) linterLog.info(() => 'no errors found')
291+
292+
diagsList.forEach(d => {
278293
if (win) d.uri = d.uri.replace('file://C:', 'file:///c%3A')
279294
connection.sendDiagnostics({uri: d.uri, diagnostics: d.diag})
280295
})
@@ -293,7 +308,8 @@ function processErrors(out: string, docURI: string, diagnostics: Map<string, Dia
293308

294309
const diag: Diagnostic = {
295310
severity: error.type,
296-
range: calcRange(error.line - ((!hasDirective && includeGraph.get(fileName).parents.size === 0) ? 2 : 1), fileName),
311+
range: calcRange(error.line, fileName),
312+
//range: calcRange(error.line - ((!hasDirective && includeGraph.get(fileName).parents.size === 0) ? 2 : 1), fileName),
297313
message: `Line ${error.line + 1} ${replaceWords(error.msg)}`,
298314
source: 'mc-glsl'
299315
}
@@ -332,15 +348,15 @@ const daigsArray = (diags: Map<string, Diagnostic[]>) => Array.from(diags).map(k
332348

333349
const filterMatches = (output: string) => output
334350
.split('\n')
335-
.filter(s => s.length > 1 && !filters.some(reg => reg.test(s)))
351+
.filter(s => s.length > 1 && !errorFilters.some(reg => reg.test(s)))
336352
.map(s => s.match(reDiag))
337353
.filter(match => match && match.length === 5)
338354

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

342358
const lines = getDocumentContents(uri).split('\n')
343-
const line = lines[lineNum]
359+
const line = lines[Math.min(Math.max(lineNum, 0), lines.length - 1)]
344360
const startOfLine = line.length - line.trimLeft().length
345361
const endOfLine = line.trimRight().length + 1
346362
//const endOfLine = line.slice(0, line.indexOf('//')).trimRight().length + 2

0 commit comments

Comments
 (0)