Skip to content

Commit aa71d44

Browse files
authored
Merge pull request #277 from Pivot-Studio/feat/npm_pkg
feat: add npm pkg && support std lib in wasm lsp
2 parents 6908212 + 5618f91 commit aa71d44

File tree

16 files changed

+173
-68
lines changed

16 files changed

+173
-68
lines changed

.github/workflows/npmpkg.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Publish Package to npmjs
2+
on:
3+
push:
4+
tags:
5+
- 'wasm/*'
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
- uses: actions-rs/toolchain@v1
12+
name: Install Rust (stable)
13+
- uses: actions-rs/toolchain@v1
14+
with:
15+
profile: minimal
16+
override: true
17+
- name: install rust
18+
run: cargo install wasm-pack
19+
- name: build wasm
20+
run: wasm-pack build --target bundler --no-default-features --scope pivot-lang --release
21+
# Setup .npmrc file to publish to npm
22+
- uses: actions/setup-node@v3
23+
with:
24+
node-version: '16.x'
25+
registry-url: 'https://registry.npmjs.org'
26+
- run: cd pkg && npm publish --access public
27+
env:
28+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.vscode/settings.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,11 @@
2222
"tuple": "cpp",
2323
"test1.c": "cpp"
2424
},
25-
"C_Cpp.errorSquiggles": "enabled"
25+
"C_Cpp.errorSquiggles": "enabled",
26+
// "rust-analyzer.check.targets": [
27+
// "wasm32-unknown-unknown",
28+
// ],
29+
// "rust-analyzer.cargo.target": "wasm32-unknown-unknown",
30+
// "rust-analyzer.cargo.noDefaultFeatures": true,
31+
// "rust-analyzer.check.noDefaultFeatures": true
2632
}

Cargo.lock

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

Cargo.toml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ authors = ["The pivot-lang Authors"]
88

99
[dependencies]
1010
inkwell = { version = "0.1", optional = true, features = ["llvm14-0", "no-libffi-linking"] }
11+
llvm-sys = { version = "140", optional = true }
12+
pl_linker = { path = "./pl_linker", optional = true }
13+
immix = { path = "./immix", optional = true, features = ["llvm_gc_plugin", "llvm_stackmap"] }
14+
vm = { path = "./vm", optional = true, features = ["jit"] }
1115
indexmap = "1.9"
1216
lazy_static = "1.4"
1317
paste = "1.0"
14-
llvm-sys = { version = "140", optional = true }
1518
internal_macro = { path = "./internal_macro", default-features = false }
16-
pl_linker = { path = "./pl_linker", optional = true }
17-
vm = { path = "./vm", optional = true, features = ["jit"] }
18-
immix = { path = "./immix", optional = true, features = ["llvm_gc_plugin", "llvm_stackmap"] }
1919
nom_locate = "4.0"
2020
rowan = "0.15"
2121
dissimilar = "1.0"
@@ -45,8 +45,9 @@ console = "0.15"
4545

4646
[target.'cfg(target_arch = "wasm32")'.dependencies]
4747
wasm-bindgen = "0.2"
48-
console_error_panic_hook = "0.1.7"
49-
wasm-logger = "0.2.0"
48+
console_error_panic_hook = "0.1"
49+
wasm-logger = "0.2"
50+
include_dir = "0.7"
5051

5152

5253
[dependencies.nom]

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ cmake-clean:
4141
@find . -name CMakeCache.txt -type f -delete
4242

4343
lsp-wasm:
44-
@wasm-pack build --target bundler --no-default-features
44+
@wasm-pack build --target bundler --no-default-features --scope pivot-lang

src/ast/node/pkg.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ impl Node for UseNode {
5555
ctx: &'b mut Ctx<'a>,
5656
_builder: &'b BuilderEnum<'a, 'ctx>,
5757
) -> NodeResult {
58+
#[cfg(target_arch = "wasm32")]
59+
let mut path = PathBuf::from("");
60+
#[cfg(not(target_arch = "wasm32"))]
5861
let mut path = PathBuf::from(&ctx.config.root);
5962
let head = self.ids[0].get_name(ctx);
6063
if !self.ids.is_empty() {
@@ -73,6 +76,13 @@ impl Node for UseNode {
7376
for v in self.ids.iter() {
7477
ctx.push_semantic_token(v.range, SemanticTokenType::NAMESPACE, 0);
7578
}
79+
#[cfg(target_arch = "wasm32")]
80+
if crate::lsp::wasm::PLLIB_DIR
81+
.get_file(path.with_extension("pi"))
82+
.is_some()
83+
{
84+
return Ok(Default::default());
85+
}
7686
if !path.with_extension("pi").exists() {
7787
let mut path = path.with_extension("");
7888
if !path.exists() {

src/ast/node/program.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl Program {
170170
let binding = PathBuf::from(self.params(db).file(db)).with_extension("");
171171
let pkgname = binding.file_name().unwrap().to_str().unwrap();
172172
// 默认加入gc和builtin module
173-
#[cfg(not(target_arch = "wasm32"))] // TODO support std on wasm
173+
// #[cfg(not(target_arch = "wasm32"))] // TODO support std on wasm
174174
if pkgname != "gc" && pkgname != "builtin" {
175175
prog.uses.extend_from_slice(&DEFAULT_USE_NODES);
176176
}
@@ -421,7 +421,7 @@ pub fn emit_file(db: &dyn Db, params: ProgramEmitParam) -> ModWrapper {
421421
);
422422
ctx.plmod.submods = params.submods(db);
423423
// imports all builtin symbols
424-
#[cfg(not(target_arch = "wasm32"))] // TODO support std on wasm
424+
// #[cfg(not(target_arch = "wasm32"))] // TODO support std on wasm
425425
if ctx.plmod.name != "builtin" && ctx.plmod.name != "gc" {
426426
let builtin_mod = ctx.plmod.submods.get("builtin").unwrap().clone();
427427
ctx.plmod.import_all_public_symbols_from(&builtin_mod);

src/lsp/lspserver.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -317,14 +317,14 @@ fn main_loop(
317317
});
318318
}
319319
})
320-
.on::<DocumentSymbolRequest, _>(|id, params| {
321-
let uri = url_to_path(params.text_document.uri);
322-
docin.set_file(&mut db).to(uri);
323-
docin.set_action(&mut db).to(ActionType::DocSymbol);
324-
docin
325-
.set_params(&mut db)
326-
.to(Some((Default::default(), None)));
327-
compile_dry(&db, docin);
320+
.on::<DocumentSymbolRequest, _>(|id, _| {
321+
// let uri = url_to_path(params.text_document.uri);
322+
// docin.set_file(&mut db).to(uri);
323+
// docin.set_action(&mut db).to(ActionType::DocSymbol);
324+
// docin
325+
// .set_params(&mut db)
326+
// .to(Some((Default::default(), None)));
327+
// compile_dry(&db, docin);
328328
let doc_symbols = compile_dry::accumulated::<DocSymbols>(&db, docin);
329329
let sender = connection.sender.clone();
330330
if !doc_symbols.is_empty() {

src/lsp/mem_docs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,10 @@ impl MemDocs {
200200
pub fn get_file_content(&mut self, db: &dyn Db, key: &str) -> Option<SourceProgram> {
201201
// let sanitized = crate::utils::canonicalize(key).unwrap();
202202
// let key = sanitized.to_str().unwrap();
203-
debug!("mdmdoc get_file_content {}", key);
203+
debug!("memdoc get_file_content {}", key);
204204
let mem = self.get(key);
205205
if let Some(mem) = mem {
206-
debug!("mdmdoc get_file_content result \n{}", mem.text(db));
206+
debug!("memdoc get_file_content result \n{}", mem.text(db));
207207
return Some(*mem);
208208
}
209209
let re = read_to_string(key);

src/lsp/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ pub mod text;
99
#[cfg(not(target_arch = "wasm32"))]
1010
pub use lspserver::*;
1111
#[cfg(target_arch = "wasm32")]
12-
mod wasm;
12+
pub mod wasm;

0 commit comments

Comments
 (0)