Skip to content

Commit

Permalink
hls 0.4, colors, project config, rvmat
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettMayson committed Jan 18, 2025
1 parent a7111c6 commit 37c3947
Show file tree
Hide file tree
Showing 12 changed files with 368 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ if (_uniform == "") exitWith {};
if (isNil "ps_cam") then {
ps_cam = "camera" camCreate [0,0,0];
};

ps_cam cameraEffect ["INTERNAL", "BACK"];
ps_cam camSetTarget objNull;
ps_cam camSetDir vectorDir camera_uniform;
ps_cam camSetPos getPos camera_uniform;
hideObject camera_uniform;
Expand Down
9 changes: 8 additions & 1 deletion hls/languages/config.configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@
"lineComment": "//",
"blockComment": ["/*", "*/"]
},
"brackets": [["{", "}"]],
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"]
],
"autoClosingPairs": [
["[", "]"],
["\"", "\""],
["(", ")"],
["{", "}"]
],
"surroundingPairs": [
["(", ")"],
["[", "]"],
["{", "}"],
["'", "'"],
["\"", "\""]
]
Expand Down
80 changes: 51 additions & 29 deletions hls/languages/config.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"scopeName": "config",
"fileTypes": [
"ext"
"ext",
"cpp",
"sqm",
"rvmat"
],
"name": "ext",
"name": "arma-config",
"patterns": [
{
"include": "#strings"
Expand All @@ -15,21 +18,40 @@
"include": "#comments"
},
{
"name": "storage.type",
"match": "\\b(class)\\b"
"name": "meta.class.declaration.arma_config",
"match": "\\b(class)\\s+([a-zA-Z_][a-zA-Z0-9_]*)(?:\\s*\\:\\s*([a-zA-Z_][a-zA-Z0-9_]*))?",
"captures": {
"1": {
"name": "storage.type.arma_config"
},
"2": {
"name": "entity.name.class.arma_config"
},
"3": {
"name": "entity.other.inherited-class.arma_config"
}
}
},
{
"name": "support.function.macro.arma_config",
"match": "\\b([a-zA-Z_][a-zA-Z0-9_]*)(?=\\s*\\()"
},
{
"name": "variable.other.arma_config",
"match": "\\b([a-zA-Z_][a-zA-Z0-9_]*)\\b(?=\\s*(?:\\[\\])?\\s*=)"
},
{
"begin": "^\\s*((#)\\s*(include(?:_next)?|import))\\b\\s*",
"beginCaptures": {
"1": {
"name": "keyword.control.directive.$3.ext"
"name": "keyword.control.directive.$3.arma_config"
},
"2": {
"name": "punctuation.definition.directive.ext"
"name": "punctuation.definition.directive.arma_config"
}
},
"end": "(?=(?://|/\\*))|(?<!\\\\)(?=\\n)",
"name": "meta.preprocessor.include.ext",
"name": "meta.preprocessor.include.arma_config",
"patterns": [
{
"include": "#line_continuation_character"
Expand All @@ -38,31 +60,31 @@
"begin": "\"",
"beginCaptures": {
"0": {
"name": "punctuation.definition.string.begin.ext"
"name": "punctuation.definition.string.begin.arma_config"
}
},
"end": "\"",
"endCaptures": {
"0": {
"name": "punctuation.definition.string.end.ext"
"name": "punctuation.definition.string.end.arma_config"
}
},
"name": "string.quoted.double.include.ext"
"name": "string.quoted.double.include.arma_config"
},
{
"begin": "<",
"beginCaptures": {
"0": {
"name": "punctuation.definition.string.begin.ext"
"name": "punctuation.definition.string.begin.arma_config"
}
},
"end": ">",
"endCaptures": {
"0": {
"name": "punctuation.definition.string.end.ext"
"name": "punctuation.definition.string.end.arma_config"
}
},
"name": "string.quoted.other.lt-gt.include.ext"
"name": "string.quoted.other.lt-gt.include.arma_config"
}
]
},
Expand Down Expand Up @@ -92,7 +114,7 @@
}
},
"end": "(?=(?://|/\\*))|(?<!\\\\)(?=\\n)",
"name": "meta.preprocessor.macro.ext"
"name": "meta.preprocessor.macro.arma_config"
}
],
"repository": {
Expand All @@ -112,7 +134,7 @@
"patterns": [
{
"match": "\\b((0(x|X)[0-9a-fA-F]([0-9a-fA-F']*[0-9a-fA-F])?)|(0(b|B)[01]([01']*[01])?)|(([0-9]([0-9']*[0-9])?\\.?[0-9]*([0-9']*[0-9])?)|(\\.[0-9]([0-9']*[0-9])?))((e|E)(\\+|-)?[0-9]([0-9']*[0-9])?)?)(L|l|UL|ul|u|U|F|f|ll|LL|ull|ULL)?\\b",
"name": "constant.numeric.ext"
"name": "constant.numeric.arma_config"
}
]
},
Expand Down Expand Up @@ -189,61 +211,61 @@
"begin": "(u|u8|U|L)?\"",
"beginCaptures": {
"0": {
"name": "punctuation.definition.string.begin.ext"
"name": "punctuation.definition.string.begin.arma_config"
},
"1": {
"name": "meta.encoding.ext"
"name": "meta.encoding.arma_config"
}
},
"end": "\"",
"endCaptures": {
"0": {
"name": "punctuation.definition.string.end.ext"
"name": "punctuation.definition.string.end.arma_config"
}
},
"name": "string.quoted.double.ext",
"name": "string.quoted.double.arma_config",
"patterns": [
{
"match": "\\\\u\\h{4}|\\\\U\\h{8}",
"name": "constant.character.escape.ext"
"name": "constant.character.escape.arma_config"
},
{
"match": "\\\\['\"?\\\\abfnrtv]",
"name": "constant.character.escape.ext"
"name": "constant.character.escape.arma_config"
},
{
"match": "\\\\[0-7]{1,3}",
"name": "constant.character.escape.ext"
"name": "constant.character.escape.arma_config"
},
{
"match": "\\\\x\\h+",
"name": "constant.character.escape.ext"
"name": "constant.character.escape.arma_config"
}
]
},
{
"begin": "(u|u8|U|L)?R\"(?:([^ ()\\\\\\t]{0,16})|([^ ()\\\\\\t]*))\\(",
"beginCaptures": {
"0": {
"name": "punctuation.definition.string.begin.ext"
"name": "punctuation.definition.string.begin.arma_config"
},
"1": {
"name": "meta.encoding.ext"
"name": "meta.encoding.arma_config"
},
"3": {
"name": "invalid.illegal.delimiter-too-long.ext"
"name": "invalid.illegal.delimiter-too-long.arma_config"
}
},
"end": "\\)\\2(\\3)\"",
"endCaptures": {
"0": {
"name": "punctuation.definition.string.end.ext"
"name": "punctuation.definition.string.end.arma_config"
},
"1": {
"name": "invalid.illegal.delimiter-too-long.ext"
"name": "invalid.illegal.delimiter-too-long.arma_config"
}
},
"name": "string.quoted.double.raw.ext"
"name": "string.quoted.double.raw.arma_config"
}
]
}
Expand Down
10 changes: 5 additions & 5 deletions hls/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions hls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "hemtt",
"description": "HEMTT Language Server & Utils",
"license": "MIT",
"version": "0.3.1",
"version": "0.4.0",
"publisher": "brettmayson",
"icon": "icon.png",
"categories": [],
Expand Down Expand Up @@ -55,7 +55,8 @@
"extensions": [
".ext",
".hpp",
".sqm"
".sqm",
".rvmat"
],
"filenames": [
"config.cpp"
Expand Down
121 changes: 121 additions & 0 deletions hls/src/color.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
use regex::Regex;
use tower_lsp::lsp_types::{
ColorInformation, ColorPresentation, ColorPresentationParams, Position, Range,
};
use tower_lsp::{jsonrpc::Result, lsp_types::Color};
use tracing::debug;
use url::Url;

use crate::files::FileCache;

pub async fn info(url: Url) -> Result<Vec<ColorInformation>> {
let regex = Regex::new(r"(?m)\#\((\w+),(\d+),(\d+),(\d+)\)color\(([\d|\.]+),([\d|\.]+),([\d|\.]+),([\d|\.]+)(?:,(\w+))?\)").unwrap();

let Some(text) = FileCache::get().text(&url) else {
return Ok(vec![]);
};

let mut colors = Vec::new();
for mat in regex.captures_iter(&text) {
if !["rgb", "argb"].contains(&mat.get(1).unwrap().as_str()) {
continue;
}
debug!("Found color: {:?}", mat);
let start = offset_to_line_and_char(&text, mat.get(0).unwrap().start());
let end = offset_to_line_and_char(&text, mat.get(0).unwrap().end());
colors.push(ColorInformation {
range: Range {
start: Position {
line: start.0,
character: start.1,
},
end: Position {
line: end.0,
character: end.1,
},
},
color: Color {
red: mat.get(5).unwrap().as_str().parse().unwrap(),
green: mat.get(6).unwrap().as_str().parse().unwrap(),
blue: mat.get(7).unwrap().as_str().parse().unwrap(),
alpha: mat.get(8).unwrap().as_str().parse().unwrap(),
},
});
}

Ok(colors)
}

pub async fn presentation(params: ColorPresentationParams) -> Result<Vec<ColorPresentation>> {
let regex = Regex::new(r"(?m)\#\((\w+),(\d+),(\d+),(\d+)\)color\(([\d|\.]+),([\d|\.]+),([\d|\.]+),([\d|\.]+)(?:,(\w+))?\)").unwrap();

let Some(text) = FileCache::get().text(&params.text_document.uri) else {
return Ok(vec![]);
};

for mat in regex.captures_iter(&text) {
let start = offset_to_line_and_char(&text, mat.get(0).unwrap().start());
let end = offset_to_line_and_char(&text, mat.get(0).unwrap().end());
let range = Range {
start: Position {
line: start.0,
character: start.1,
},
end: Position {
line: end.0,
character: end.1,
},
};
if range == params.range {
return Ok(vec![ColorPresentation {
label: if let Some(texture_type) = mat.get(9) {
format!(
"#({},{},{},{})color({},{},{},{},{})",
mat.get(1).unwrap().as_str(),
mat.get(2).unwrap().as_str(),
mat.get(3).unwrap().as_str(),
mat.get(4).unwrap().as_str(),
params.color.red,
params.color.green,
params.color.blue,
params.color.alpha,
texture_type.as_str()
)
} else {
format!(
"#({},{},{},{})color({},{},{},{})",
mat.get(1).unwrap().as_str(),
mat.get(2).unwrap().as_str(),
mat.get(3).unwrap().as_str(),
mat.get(4).unwrap().as_str(),
params.color.red,
params.color.green,
params.color.blue,
params.color.alpha
)
},
text_edit: None,
additional_text_edits: None,
}]);
}
}

Ok(vec![])
}

fn offset_to_line_and_char(text: &str, offset: usize) -> (u32, u32) {
let mut line = 0;
let mut col = 0;
for (i, c) in text.chars().enumerate() {
if i == offset {
break;
}
if c == '\n' {
line += 1;
col = 0;
} else {
col += 1;
}
}
(line as u32, col as u32)
}
Loading

0 comments on commit 37c3947

Please sign in to comment.