mirror of
https://github.com/Strum355/mcshader-lsp.git
synced 2025-08-31 13:57:27 +00:00
Collecting includes, getting shader type from extension:
This commit is contained in:
parent
7259283c6e
commit
960597e324
4 changed files with 29 additions and 10 deletions
|
@ -6,7 +6,7 @@ Want to contribute? I sure want you to! Heres how you can help:
|
|||
|
||||
Development requirements (did I miss any? Submit a PR!):
|
||||
|
||||
`npm, nodejs, tslint, VSCode`
|
||||
`git`, `npm`, `nodejs`, `VSCode`, (optional) `python3`
|
||||
|
||||
Fork the repo (you are using [SSH keys](https://help.github.com/articles/connecting-to-github-with-ssh/), right?):
|
||||
|
||||
|
@ -16,14 +16,17 @@ Install dependencies:
|
|||
|
||||
`cd vscode-mc-shader/server && npm i && cd ../client && npm i`
|
||||
|
||||
If you dont have glslangValidator installed, run the following in the root directory of the repo and follow the instructions:
|
||||
`python3 setup.py`
|
||||
|
||||
Follow [this](https://code.visualstudio.com/docs/extensions/overview) link to learn your way around making extensions as well as [here](https://code.visualstudio.com/docs/extensions/example-language-server) to learn a bit about the Language Server Protocol.
|
||||
|
||||
To test out your changes, simply choose `Launch Client` in the debug menu.
|
||||
To test out your changes, choose `Launch Client` in the debug menu or press `F5`.
|
||||
|
||||
## Submitting a Pull Request
|
||||
|
||||
Please adhere to the following guidelines before submitting a pull request:
|
||||
|
||||
- Passes tslint checks with the given config.
|
||||
- Provide some comments in the code (see mine as an example).
|
||||
- Provide some comments in the code where applicable.
|
||||
- Provide a good explanation of the changes provided. This helps me follow your code better.
|
|
@ -2,9 +2,11 @@ import { conf, connection, documents } from './server'
|
|||
import './global'
|
||||
import { TextDocument, Diagnostic, DiagnosticSeverity, Range } from 'vscode-languageserver';
|
||||
import { exec } from 'child_process'
|
||||
import * as path from 'path'
|
||||
|
||||
const reDiag = /(ERROR|WARNING): (?:\d):(\d+): '(?:.*)' : (.+)/
|
||||
const reVersion = /#version [\d]{3}/
|
||||
const reInclude = /^(?: |\t)*(?:#include) "((?:\/[\S]+)+\.(?:glsl))"$/
|
||||
const include = '#extension GL_GOOGLE_include_directive : require'
|
||||
|
||||
const filters = [
|
||||
|
@ -12,6 +14,13 @@ const filters = [
|
|||
/(compilation terminated)/,
|
||||
]
|
||||
|
||||
const ext = {
|
||||
'.fsh': 'frag',
|
||||
'.gsh': 'geom',
|
||||
'.vsh': 'vert',
|
||||
'.glsl': 'frag'
|
||||
}
|
||||
|
||||
const tokens: {[key: string]: string} = {
|
||||
'SEMICOLON': ';',
|
||||
'COMMA': ',',
|
||||
|
@ -55,7 +64,8 @@ const replaceWord = (msg: string) => {
|
|||
}
|
||||
|
||||
export function preprocess(document: TextDocument) {
|
||||
const lines = document.getText().split('\n')
|
||||
const lines = document.getText().split('\n').map(s => s.replace(/^\s+|\s+$/g, ''))
|
||||
const includes = getIncludes(lines)
|
||||
let inComment = false
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const line = lines[i]
|
||||
|
@ -69,12 +79,12 @@ export function preprocess(document: TextDocument) {
|
|||
if (i === lines.length - 1) lines.splice(0, 0, include)
|
||||
}
|
||||
|
||||
//const root = document.uri.replace(/^file:\/\//, '').replace(conf.minecraftPath, '').replace(path.basename(document.uri), '')
|
||||
lint(lines.join('\n'), document.uri)
|
||||
const root = document.uri.replace(/^file:\/\//, '').replace(path.basename(document.uri), '')
|
||||
lint(path.extname(document.uri.replace(/^file:\/\//, '')), lines.join('\n'), document.uri)
|
||||
}
|
||||
|
||||
function lint(text: string, uri: string) {
|
||||
const child = exec(`${conf.glslangPath} --stdin -S frag`, (error, out, err) => {
|
||||
function lint(extension: string, text: string, uri: string) {
|
||||
const child = exec(`${conf.glslangPath} --stdin -S ${ext[extension]}`, (error, out) => {
|
||||
const diagnostics: Diagnostic[] = []
|
||||
const matches = filterMatches(out) as RegExpMatchArray[]
|
||||
matches.forEach((match) => {
|
||||
|
@ -99,4 +109,8 @@ function calcRange(lineNum: number, uri: string): Range {
|
|||
|
||||
function prepareLine(line: string): string {
|
||||
return line.slice(0, line.indexOf('//')).rightTrim()
|
||||
}
|
||||
|
||||
function getIncludes(lines: string[]): {lineNum: number, match: RegExpMatchArray}[] {
|
||||
return lines.map((line, i) => ({num: i, line})).filter((obj) => reInclude.test(obj.line)).map((obj) => ({lineNum: obj.num, match: obj.line.match(reInclude)}))
|
||||
}
|
|
@ -8,6 +8,7 @@
|
|||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"no-string-literal": false,
|
||||
"array-type": false,
|
||||
"interface-name": false,
|
||||
"indent": [true, "spaces", 2],
|
||||
"arrow-parens": false,
|
||||
|
|
5
setup.py
5
setup.py
|
@ -20,14 +20,15 @@ def main():
|
|||
os_choice = int(input('Choose your OS:\n - 0: Windows\n - 1: Linux\n - 2: OSX\n> '))
|
||||
if os_choice not in os:
|
||||
print('Invalid OS. Please only choose a value between 0 and 2')
|
||||
|
||||
exit(1)
|
||||
print('Downloading...')
|
||||
with urllib.request.urlopen(url[os_choice]) as respone:
|
||||
with BytesIO(respone.read()) as zipped:
|
||||
with zipfile.ZipFile(zipped) as zip_file:
|
||||
zip_file.extract('bin/glslangValidator')
|
||||
o.rename('bin/glslangValidator', 'glslangValidator')
|
||||
o.rmdir('bin')
|
||||
print('glslangValidator downloaded. Set mclglsl')
|
||||
print('glslangValidator downloaded. Add this line to your VSCode settings:\n"mcglsl.glslangValidatorPath": "' + o.getcwd() + '/' + 'glslangValidator"')
|
||||
return
|
||||
print('There was an error :(')
|
||||
main()
|
Loading…
Add table
Add a link
Reference in a new issue