Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update tree-sitter to latest #6231

Merged
merged 2 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
602 changes: 44 additions & 558 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion apps/wing/src/commands/lsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,14 @@ export async function lsp() {
for (const rd of raw_diagnostics) {
if (rd.span) {
const diagnosticUri = "file://" + rd.span.file_id;
let message = rd.message;
MarkMcCulloh marked this conversation as resolved.
Show resolved Hide resolved
if (rd.hints.length > 0) {
message += `\n${rd.hints.map((hint) => `hint: ${hint}`).join("\n")}`;
}

const diag = Diagnostic.create(
Range.create(rd.span.start.line, rd.span.start.col, rd.span.end.line, rd.span.end.col),
`${rd.message}\n${rd.hints.map((hint) => `hint: ${hint}`).join("\n")}`,
message,
undefined,
undefined,
undefined,
Expand Down
39 changes: 39 additions & 0 deletions libs/tree-sitter-wing/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{json,toml,yml,gyp}]
indent_style = space
indent_size = 2

[*.js]
indent_style = space
indent_size = 2

[*.rs]
indent_style = space
indent_size = 4

[*.{c,cc,h}]
indent_style = space
indent_size = 4

[*.{py,pyi}]
indent_style = space
indent_size = 4

[*.swift]
indent_style = space
indent_size = 4

[*.go]
indent_style = tab
indent_size = 8

[Makefile]
indent_style = tab
indent_size = 8
27 changes: 10 additions & 17 deletions libs/tree-sitter-wing/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
[package]
name = "tree-sitter-wing"
description = "winglang grammar for the tree-sitter parsing library"
description = "Wing grammar for tree-sitter"
version = "0.0.0"
keywords = ["incremental", "parsing", "wing"]
license = "MIT"
readme = "README.md"
keywords = ["incremental", "parsing", "tree-sitter", "wing"]
categories = ["parsing", "text-editors"]
repository = "https://github.com/winglang/wing/tree/main/libs/tree-sitter-wing"
repository = "https://github.com/winglang/tree-sitter-wing"
edition = "2021"
license = "MIT"
autoexamples = false

build = "bindings/rust/build.rs"
include = [
"bindings/rust/*",
"grammar.js",
"queries/*",
"src/*",
]
include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"]

[lib]
path = "bindings/rust/lib.rs"

[dependencies]
tree-sitter = "0.20.10"

[dev-dependencies]
tree-sitter-cli = "0.20.8"
# Waiting for https://github.com/tree-sitter/tree-sitter/pull/3293 to be released
tree-sitter = { git = "https://github.com/tree-sitter/tree-sitter.git", rev = "a7a47d561d4e64eaf226f93c4d68076afa67fdda" }

[build-dependencies]
cc = "1.0"
tree-sitter-cli = "0.20.8"
tree-sitter = "0.20.10"
cc = "1.0.87"
112 changes: 112 additions & 0 deletions libs/tree-sitter-wing/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
VERSION := 0.0.0

LANGUAGE_NAME := tree-sitter-wing

# repository
SRC_DIR := src

PARSER_REPO_URL := $(shell git -C $(SRC_DIR) remote get-url origin 2>/dev/null)

ifeq ($(PARSER_URL),)
PARSER_URL := $(subst .git,,$(PARSER_REPO_URL))
ifeq ($(shell echo $(PARSER_URL) | grep '^[a-z][-+.0-9a-z]*://'),)
PARSER_URL := $(subst :,/,$(PARSER_URL))
PARSER_URL := $(subst git@,https://,$(PARSER_URL))
endif
endif

TS ?= tree-sitter

# ABI versioning
SONAME_MAJOR := $(word 1,$(subst ., ,$(VERSION)))
SONAME_MINOR := $(word 2,$(subst ., ,$(VERSION)))

# install directory layout
PREFIX ?= /usr/local
INCLUDEDIR ?= $(PREFIX)/include
LIBDIR ?= $(PREFIX)/lib
PCLIBDIR ?= $(LIBDIR)/pkgconfig

# source/object files
PARSER := $(SRC_DIR)/parser.c
EXTRAS := $(filter-out $(PARSER),$(wildcard $(SRC_DIR)/*.c))
OBJS := $(patsubst %.c,%.o,$(PARSER) $(EXTRAS))

# flags
ARFLAGS ?= rcs
override CFLAGS += -I$(SRC_DIR) -std=c11 -fPIC

# OS-specific bits
ifeq ($(OS),Windows_NT)
$(error "Windows is not supported")
else ifeq ($(shell uname),Darwin)
SOEXT = dylib
SOEXTVER_MAJOR = $(SONAME_MAJOR).dylib
SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).dylib
LINKSHARED := $(LINKSHARED)-dynamiclib -Wl,
ifneq ($(ADDITIONAL_LIBS),)
LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS),
endif
LINKSHARED := $(LINKSHARED)-install_name,$(LIBDIR)/lib$(LANGUAGE_NAME).$(SONAME_MAJOR).dylib,-rpath,@executable_path/../Frameworks
else
SOEXT = so
SOEXTVER_MAJOR = so.$(SONAME_MAJOR)
SOEXTVER = so.$(SONAME_MAJOR).$(SONAME_MINOR)
LINKSHARED := $(LINKSHARED)-shared -Wl,
ifneq ($(ADDITIONAL_LIBS),)
LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS)
endif
LINKSHARED := $(LINKSHARED)-soname,lib$(LANGUAGE_NAME).so.$(SONAME_MAJOR)
endif
ifneq ($(filter $(shell uname),FreeBSD NetBSD DragonFly),)
PCLIBDIR := $(PREFIX)/libdata/pkgconfig
endif

all: lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT) $(LANGUAGE_NAME).pc

lib$(LANGUAGE_NAME).a: $(OBJS)
$(AR) $(ARFLAGS) $@ $^

lib$(LANGUAGE_NAME).$(SOEXT): $(OBJS)
$(CC) $(LDFLAGS) $(LINKSHARED) $^ $(LDLIBS) -o $@
ifneq ($(STRIP),)
$(STRIP) $@
endif

$(LANGUAGE_NAME).pc: bindings/c/$(LANGUAGE_NAME).pc.in
sed -e 's|@URL@|$(PARSER_URL)|' \
-e 's|@VERSION@|$(VERSION)|' \
-e 's|@LIBDIR@|$(LIBDIR)|' \
-e 's|@INCLUDEDIR@|$(INCLUDEDIR)|' \
-e 's|@REQUIRES@|$(REQUIRES)|' \
-e 's|@ADDITIONAL_LIBS@|$(ADDITIONAL_LIBS)|' \
-e 's|=$(PREFIX)|=$${prefix}|' \
-e 's|@PREFIX@|$(PREFIX)|' $< > $@

$(PARSER): $(SRC_DIR)/grammar.json
$(TS) generate --no-bindings $^

install: all
install -d '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter '$(DESTDIR)$(PCLIBDIR)' '$(DESTDIR)$(LIBDIR)'
install -m644 bindings/c/$(LANGUAGE_NAME).h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h
install -m644 $(LANGUAGE_NAME).pc '$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc
install -m644 lib$(LANGUAGE_NAME).a '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a
install -m755 lib$(LANGUAGE_NAME).$(SOEXT) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER)
ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR)
ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT)

uninstall:
$(RM) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a \
'$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER) \
'$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) \
'$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT) \
'$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h \
'$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc

clean:
$(RM) $(OBJS) $(LANGUAGE_NAME).pc lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT)

test:
$(TS) test

.PHONY: all install uninstall clean test
47 changes: 47 additions & 0 deletions libs/tree-sitter-wing/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// swift-tools-version:5.3
import PackageDescription

let package = Package(
name: "TreeSitterWing",
products: [
.library(name: "TreeSitterWing", targets: ["TreeSitterWing"]),
],
dependencies: [],
targets: [
.target(name: "TreeSitterWing",
path: ".",
exclude: [
"Cargo.toml",
"Makefile",
"binding.gyp",
"bindings/c",
"bindings/go",
"bindings/node",
"bindings/python",
"bindings/rust",
"prebuilds",
"grammar.js",
"package.json",
"package-lock.json",
"pyproject.toml",
"setup.py",
"test",
"examples",
".editorconfig",
".github",
".gitignore",
".gitattributes",
".gitmodules",
],
sources: [
"src/parser.c",
"src/scanner.c",
],
resources: [
.copy("queries")
],
publicHeadersPath: "bindings/swift",
cSettings: [.headerSearchPath("src")])
],
cLanguageStandard: .c11
)
18 changes: 4 additions & 14 deletions libs/tree-sitter-wing/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
# tree-sitter-wing

TODO
A tree-sitter parser for the Wing language.

## Build
Wing is still heavily in development and this grammar/parser is experimental. It is used directly in the Wing compiler and is not considered a public API. It is available here for use but may have breaking changes at any time and no bindings are published or guaranteed to be work.

```sh
cargo build
```
## Contributing

## Test

```sh
cargo test
```

## License

Licensed under the MIT license.
Issues are tracked as part of the [Wing](https://github.com/winglang/wing) repository.
23 changes: 17 additions & 6 deletions libs/tree-sitter-wing/binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,29 @@
"targets": [
{
"target_name": "tree_sitter_wing_binding",
"dependencies": [
"<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except",
],
"include_dirs": [
"<!(node -e \"require('nan')\")",
"src"
"src",
],
"sources": [
"bindings/node/binding.cc",
"src/parser.c",
# If your language uses an external scanner, add it here.
"src/scanner.c"
],
"conditions": [
["OS!='win'", {
"cflags_c": [
"-std=c11",
],
}, { # OS == "win"
"cflags_c": [
"/std:c11",
"/utf-8",
],
}],
],
"cflags_c": [
"-std=c99",
]
}
]
}
16 changes: 16 additions & 0 deletions libs/tree-sitter-wing/bindings/c/tree-sitter-wing.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef TREE_SITTER_WING_H_
#define TREE_SITTER_WING_H_

typedef struct TSLanguage TSLanguage;

#ifdef __cplusplus
extern "C" {
#endif

const TSLanguage *tree_sitter_wing(void);

#ifdef __cplusplus
}
#endif

#endif // TREE_SITTER_WING_H_
11 changes: 11 additions & 0 deletions libs/tree-sitter-wing/bindings/c/tree-sitter-wing.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
prefix=@PREFIX@
libdir=@LIBDIR@
includedir=@INCLUDEDIR@

Name: tree-sitter-wing
Description: Wing grammar for tree-sitter
URL: @URL@
Version: @VERSION@
Requires: @REQUIRES@
Libs: -L${libdir} @ADDITIONAL_LIBS@ -ltree-sitter-wing
Cflags: -I${includedir}
13 changes: 13 additions & 0 deletions libs/tree-sitter-wing/bindings/go/binding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package tree_sitter_wing

// #cgo CFLAGS: -std=c11 -fPIC
// #include "../../src/parser.c"
// // NOTE: if your language has an external scanner, add it here.
import "C"

import "unsafe"

// Get the tree-sitter Language for this grammar.
func Language() unsafe.Pointer {
return unsafe.Pointer(C.tree_sitter_wing())
}
15 changes: 15 additions & 0 deletions libs/tree-sitter-wing/bindings/go/binding_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package tree_sitter_wing_test

import (
"testing"

tree_sitter "github.com/smacker/go-tree-sitter"
"github.com/winglang/tree-sitter-wing"
)

func TestCanLoadGrammar(t *testing.T) {
language := tree_sitter.NewLanguage(tree_sitter_wing.Language())
if language == nil {
t.Errorf("Error loading Wing grammar")
}
}
5 changes: 5 additions & 0 deletions libs/tree-sitter-wing/bindings/go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/winglang/tree-sitter-wing

go 1.22

require github.com/smacker/go-tree-sitter v0.0.0-20230720070738-0d0a9f78d8f8
Loading
Loading