pr 08 lsp
This commit is contained in:
parent
06b49cf433
commit
5cf77359fb
33
crates/prometeu-lsp/tests/adapters.rs
Normal file
33
crates/prometeu-lsp/tests/adapters.rs
Normal file
@ -0,0 +1,33 @@
|
||||
use prometeu_analysis::TextIndex;
|
||||
|
||||
#[test]
|
||||
fn span_to_range_uses_utf16() {
|
||||
// "ação" has: a (1), ç (1 utf16, BMP), ã (1 utf16, BMP), o (1) → total 4 utf16 units
|
||||
let s = "ação\n"; // newline to ensure line indexing works
|
||||
let idx = TextIndex::new(s);
|
||||
|
||||
// Byte offsets for each char boundary
|
||||
let bytes: Vec<u32> = s.char_indices().map(|(i, _)| i as u32).collect();
|
||||
// last boundary is newline; the previous is end of line content
|
||||
let end_of_line = bytes[bytes.len() - 1];
|
||||
let (line, col) = idx.byte_to_lsp(end_of_line);
|
||||
assert_eq!(line, 0);
|
||||
assert_eq!(col, 4, "UTF-16 column should be 4 for 'ação'");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn position_to_byte_roundtrip() {
|
||||
let s = "😀a\n"; // emoji is surrogate pair in UTF-16
|
||||
let idx = TextIndex::new(s);
|
||||
// emoji (😀) occupies 2 utf16 code units; 'a' adds 1
|
||||
let emoji_end_byte = "😀".len() as u32; // byte length of emoji
|
||||
|
||||
// From bytes→(line,col)
|
||||
let (line, col) = idx.byte_to_lsp(emoji_end_byte);
|
||||
assert_eq!(line, 0);
|
||||
assert_eq!(col, 2, "emoji should count as 2 UTF-16 units");
|
||||
|
||||
// Back from (line,col)→bytes should land at the same boundary
|
||||
let back = idx.lsp_to_byte(line, col);
|
||||
assert_eq!(back, emoji_end_byte);
|
||||
}
|
||||
19
prometeu-vscode/language-configuration.json
Normal file
19
prometeu-vscode/language-configuration.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"comments": {
|
||||
"lineComment": "//",
|
||||
"blockComment": ["/*", "*/"]
|
||||
},
|
||||
"brackets": [
|
||||
["{", "}"],
|
||||
["[", "]"],
|
||||
["[[", "]]"],
|
||||
["(", ")"]
|
||||
],
|
||||
"autoClosingPairs": [
|
||||
{ "open": "{", "close": "}" },
|
||||
{ "open": "[", "close": "]" },
|
||||
{ "open": "[[", "close": "]]" },
|
||||
{ "open": "(", "close": ")" },
|
||||
{ "open": "\"", "close": "\"" }
|
||||
]
|
||||
}
|
||||
34
prometeu-vscode/out/extension.js
Normal file
34
prometeu-vscode/out/extension.js
Normal file
@ -0,0 +1,34 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.activate = activate;
|
||||
exports.deactivate = deactivate;
|
||||
const vscode = require("vscode");
|
||||
const node_1 = require("vscode-languageclient/node");
|
||||
let client;
|
||||
function activate(context) {
|
||||
const cfg = vscode.workspace.getConfiguration("prometeuPbs");
|
||||
const serverPath = cfg.get("serverPath");
|
||||
if (!serverPath) {
|
||||
vscode.window.showErrorMessage("Prometeu PBS: configure 'prometeuPbs.serverPath' com o caminho do bin prometeu-lsp.");
|
||||
return;
|
||||
}
|
||||
const serverOptions = {
|
||||
command: serverPath,
|
||||
args: []
|
||||
};
|
||||
const clientOptions = {
|
||||
documentSelector: [{ scheme: "file", language: "pbs" }]
|
||||
};
|
||||
client = new node_1.LanguageClient("prometeuPbsLsp", "Prometeu PBS LSP", serverOptions, clientOptions);
|
||||
// ✅ O client é “parável” no deactivate, não o start() Promise
|
||||
context.subscriptions.push({
|
||||
dispose: () => {
|
||||
void client?.stop();
|
||||
}
|
||||
});
|
||||
void client.start();
|
||||
}
|
||||
function deactivate() {
|
||||
return client?.stop();
|
||||
}
|
||||
//# sourceMappingURL=extension.js.map
|
||||
1
prometeu-vscode/out/extension.js.map
Normal file
1
prometeu-vscode/out/extension.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;AAKA,4BA8BC;AAED,gCAEC;AAvCD,iCAAiC;AACjC,qDAAkG;AAElG,IAAI,MAAkC,CAAC;AAEvC,SAAgB,QAAQ,CAAC,OAAgC;IACrD,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;IAC7D,MAAM,UAAU,GAAG,GAAG,CAAC,GAAG,CAAS,YAAY,CAAC,CAAC;IAEjD,IAAI,CAAC,UAAU,EAAE,CAAC;QACd,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAC1B,qFAAqF,CACxF,CAAC;QACF,OAAO;IACX,CAAC;IAED,MAAM,aAAa,GAAkB;QACjC,OAAO,EAAE,UAAU;QACnB,IAAI,EAAE,EAAE;KACX,CAAC;IAEF,MAAM,aAAa,GAA0B;QACzC,gBAAgB,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;KAC1D,CAAC;IAEF,MAAM,GAAG,IAAI,qBAAc,CAAC,gBAAgB,EAAE,kBAAkB,EAAE,aAAa,EAAE,aAAa,CAAC,CAAC;IAEhG,8DAA8D;IAC9D,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC;QACvB,OAAO,EAAE,GAAG,EAAE;YACV,KAAK,MAAM,EAAE,IAAI,EAAE,CAAC;QACxB,CAAC;KACJ,CAAC,CAAC;IAEH,KAAK,MAAM,CAAC,KAAK,EAAE,CAAC;AACxB,CAAC;AAED,SAAgB,UAAU;IACtB,OAAO,MAAM,EAAE,IAAI,EAAE,CAAC;AAC1B,CAAC"}
|
||||
7378
prometeu-vscode/package-lock.json
generated
Normal file
7378
prometeu-vscode/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
50
prometeu-vscode/package.json
Normal file
50
prometeu-vscode/package.json
Normal file
@ -0,0 +1,50 @@
|
||||
{
|
||||
"name": "prometeu-pbs",
|
||||
"displayName": "Prometeu PBS",
|
||||
"version": "0.0.1",
|
||||
"publisher": "local",
|
||||
"engines": {
|
||||
"vscode": "^1.85.0"
|
||||
},
|
||||
"main": "./out/extension.js",
|
||||
"contributes": {
|
||||
"languages": [
|
||||
{
|
||||
"id": "pbs",
|
||||
"aliases": [
|
||||
"PBS",
|
||||
"Prometeu Base Script"
|
||||
],
|
||||
"extensions": [
|
||||
".pbs"
|
||||
],
|
||||
"configuration": "./language-configuration.json"
|
||||
}
|
||||
],
|
||||
"configuration": {
|
||||
"type": "object",
|
||||
"title": "Prometeu PBS",
|
||||
"properties": {
|
||||
"prometeuPbs.serverPath": {
|
||||
"type": "string",
|
||||
"default": "",
|
||||
"description": "/Users/niltonconstantino/personal/workspace.personal/intrepid/prometeu/runtime/target/debug/prometeu-lsp --stdio"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"vscode-languageclient": "^9.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.0.0",
|
||||
"@types/vscode": "^1.85.0",
|
||||
"generator-code": "^1.11.17",
|
||||
"typescript": "^5.0.0",
|
||||
"yo": "^6.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"compile": "tsc -p .",
|
||||
"watch": "tsc -watch -p ."
|
||||
}
|
||||
}
|
||||
3
prometeu-vscode/settings.json
Normal file
3
prometeu-vscode/settings.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"prometeuPbs.serverPath": "/Users/niltonconstantino/personal/workspace.personal/intrepid/prometeu/runtime/target/debug/prometeu-lsp"
|
||||
}
|
||||
40
prometeu-vscode/src/extension.ts
Normal file
40
prometeu-vscode/src/extension.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import * as vscode from "vscode";
|
||||
import { LanguageClient, LanguageClientOptions, ServerOptions } from "vscode-languageclient/node";
|
||||
|
||||
let client: LanguageClient | undefined;
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
const cfg = vscode.workspace.getConfiguration("prometeuPbs");
|
||||
const serverPath = cfg.get<string>("serverPath");
|
||||
|
||||
if (!serverPath) {
|
||||
vscode.window.showErrorMessage(
|
||||
"Prometeu PBS: configure 'prometeuPbs.serverPath' com o caminho do bin prometeu-lsp."
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const serverOptions: ServerOptions = {
|
||||
command: serverPath,
|
||||
args: []
|
||||
};
|
||||
|
||||
const clientOptions: LanguageClientOptions = {
|
||||
documentSelector: [{ scheme: "file", language: "pbs" }]
|
||||
};
|
||||
|
||||
client = new LanguageClient("prometeuPbsLsp", "Prometeu PBS LSP", serverOptions, clientOptions);
|
||||
|
||||
// ✅ O client é “parável” no deactivate, não o start() Promise
|
||||
context.subscriptions.push({
|
||||
dispose: () => {
|
||||
void client?.stop();
|
||||
}
|
||||
});
|
||||
|
||||
void client.start();
|
||||
}
|
||||
|
||||
export function deactivate(): Thenable<void> | undefined {
|
||||
return client?.stop();
|
||||
}
|
||||
12
prometeu-vscode/tsconfig.json
Normal file
12
prometeu-vscode/tsconfig.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "ES2020",
|
||||
"outDir": "out",
|
||||
"rootDir": "src",
|
||||
"lib": ["ES2020"],
|
||||
"sourceMap": true,
|
||||
"strict": true
|
||||
},
|
||||
"exclude": ["node_modules", ".vscode-test"]
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user