Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Add syntax highlighting for Pkl files #61478

Merged
merged 28 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d39f29b
Initial Pkl commit
mmanela Mar 27, 2024
d33c3db
Test and snapshot working
mmanela Mar 28, 2024
ca33476
remove unintened spaces
mmanela Mar 28, 2024
b69fb9d
move extension to match how nickle was done
mmanela Mar 28, 2024
e377c21
fix lint rule
mmanela Mar 28, 2024
0dc1c2e
fix test
mmanela Mar 29, 2024
164afbb
update test to show proper elements and update to handle missing cases
mmanela Mar 29, 2024
d6c4554
add more changes
mmanela Mar 29, 2024
194439c
try
mmanela Mar 29, 2024
7346e05
multiline escape
mmanela Mar 29, 2024
9045077
minimize
mmanela Mar 29, 2024
9bbbf32
order queries better for better highlighting
mmanela Mar 29, 2024
a14f6fa
lint
mmanela Mar 29, 2024
0155cf7
add annotation
mmanela Mar 29, 2024
f4447c4
Merge branch 'main' into pkl_highlighting
mmanela Mar 29, 2024
dfb6df2
pr comments
mmanela Apr 1, 2024
4ac4e1c
merge
mmanela Apr 1, 2024
99bd690
use if chain
mmanela Apr 1, 2024
10071a9
add back nickle only code
mmanela Apr 1, 2024
890b007
build error
mmanela Apr 1, 2024
382d658
make pkl lang available in better place
mmanela Apr 1, 2024
540c774
comment
mmanela Apr 1, 2024
6ad5e80
Update lib/codeintel/languages/extensions.go
mmanela Apr 2, 2024
8dfc883
Update docker-images/syntax-highlighter/crates/syntax-analysis/querie…
mmanela Apr 2, 2024
2a0d188
Update docker-images/syntax-highlighter/crates/syntax-analysis/querie…
mmanela Apr 2, 2024
57971d8
Update docker-images/syntax-highlighter/crates/syntax-analysis/querie…
mmanela Apr 2, 2024
745e961
more fixes
mmanela Apr 3, 2024
a451ea3
Merge branch 'main' into pkl_highlighting
mmanela Apr 3, 2024
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
691 changes: 384 additions & 307 deletions docker-images/syntax-highlighter/Cargo.Bazel.lock

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions docker-images/syntax-highlighter/Cargo.lock

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
; Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
; https://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
;
; Based on https://github.com/apple/tree-sitter-pkl/blob/main/queries/highlights.scm


; Operators

"??" @operator
"@" @operator
"=" @operator
"<" @operator
">" @operator
"!" @operator
"==" @operator
"!=" @operator
"<=" @operator
">=" @operator
"&&" @operator
"||" @operator
"+" @operator
"-" @operator
"**" @operator
"*" @operator
"/" @operator
"~/" @operator
"%" @operator
"|>" @operator

"?" @operator.type
"|" @operator.type
"->" @operator.type

"," @punctuation.delimiter
":" @punctuation.delimiter
"." @punctuation.delimiter
"?." @punctuation.delimiter

"(" @punctuation.bracket
")" @punctuation.bracket
"[" @punctuation.bracket
"]" @punctuation.bracket
"{" @punctuation.bracket
"}" @punctuation.bracket

; Keywords

"abstract" @keyword
"amends" @include
"as" @keyword
"class" @keyword
"const" @keyword
"else" @keyword
"extends" @keyword
"external" @keyword
(falseLiteral) @constant.builtin
mmanela marked this conversation as resolved.
Show resolved Hide resolved
"fixed" @keyword
"for" @keyword
"function" @keyword
mmanela marked this conversation as resolved.
Show resolved Hide resolved
"hidden" @keyword
"if" @keyword
(importExpr "import" @include)
(importGlobExpr "import*" @include)
"import" @include
"import*" @include
"in" @keyword
"is" @keyword
"let" @keyword
"local" @keyword
(moduleExpr "module" @include)
"module" @keyword
"new" @keyword
"nothing" @type.builtin
(nullLiteral) @constant.builtin
mmanela marked this conversation as resolved.
Show resolved Hide resolved
"open" @keyword
"out" @keyword
(outerExpr) @variable.builtin
"read" @function.method.builtin
"read?" @function.method.builtin
"read*" @function.method.builtin
"super" @variable.builtin
(thisExpr) @variable.builtin
"throw" @function.method.builtin
"trace" @function.method.builtin
(trueLiteral) @constant.builtin
mmanela marked this conversation as resolved.
Show resolved Hide resolved
"typealias" @keyword
"unknown" @type.builtin
"when" @keyword

; Types

(clazz (identifier) @type)
(typeAlias (identifier) @type)
((identifier) @type
(#match? @type "^[A-Z]"))

(typeArgumentList
"<" @punctuation.bracket
">" @punctuation.bracket)

; Method calls

(methodCallExpr
(identifier) @function.method)

; Method definitions

(classMethod (methodHeader (identifier)) @function.method)
(objectMethod (methodHeader (identifier)) @function.method)

; Identifiers

(classProperty (identifier) @property)
(objectProperty (identifier) @property)

(parameterList (typedIdentifier (identifier) @variable.parameter))
(objectBodyParameters (typedIdentifier (identifier) @variable.parameter))

(identifier) @variable

; Literals

(stringConstant) @string
(slStringLiteral) @string
(mlStringLiteral) @string

(escapeSequence) @escape

(intLiteral) @number
(floatLiteral) @number

(interpolationExpr
"\\(" @punctuation.special
")" @punctuation.special) @embedded

(interpolationExpr
"\\#(" @punctuation.special
")" @punctuation.special) @embedded

(interpolationExpr
"\\##(" @punctuation.special
")" @punctuation.special) @embedded

(lineComment) @comment
(blockComment) @comment
(docComment) @comment


mmanela marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,6 @@ struct SublimeLanguageName {

impl SublimeLanguageName {
fn into_tree_sitter_name(self, file_info: &FileInfo<'_>) -> TreeSitterLanguageName {
if self.raw.is_empty() || self.raw.to_lowercase() == "plain text" {
#[allow(clippy::single_match)]
match file_info.extension() {
Some("ncl") => return TreeSitterLanguageName::new("nickel"),
_ => {}
};
}

// Written in an unusual style so that we can:
// 1. Avoid case-sensitive comparison
// 2. We can look up corresponding Sublime Grammars easily
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
module some.module

amends "fileB.pkl"

import "fileA.pkl" as fileA

import* "globbed/*.pkl"

impExp = import("fileC.pkl")

// Single-line comment

/*
Multiline
comment
*/


// Strings and interpolation
name = "Dodo"
greeting = "Hi, \(name)!"
x = 42
message1 = "\(x + 2) plus \(x * 2) is \(0x80)"
message2 = """
Although the \(name) is extinct,
the species will be remembered.
"""

message3 = #" \\\\\ \#n \#u{12AF} \#(name) """"" "#
message4 = ##"""
\\\\\ \#\#\# """""
multi-line with custom escape
"""##


strLength = "dodo".length
reversedStr = "dodo".reverse()
hasAx = "dodo".contains("alive")


# Functions
addToA = (b: Number) -> a + b
list = List(1, 2, 3).map(addToA)


# Operators
comparison1 = 5 == 2

# Numbers
num1 = 123
num2 = 0x012AFF


// Floats
f1: Float(isFinite) = 1.0
f2: Float(isBetween(0, 10e6))
f3 = .23
notANumber = NaN
positiveInfinity = Infinity

// Booleans
b1 = true && false
b3 = true.xor(false)


# Durations
duration1 = 5.min
xySeconds = (x + y).s


// Data Sizes
datasize1 = 5.b // bytes (smallest unit)


// Consts
const laysEggs: Boolean = true

const examples: Listing<String> = new {
"Pigeon"
"Hawk"
}

// Classes

class BunchOfTypes {
someString: String
someInt: Int
hidden someHiddenString: String
local someLocalThing = ","
}

class Bird {
name: String(length >= 3)
lifespan: UInt8
function isOlderThan(bird: Bird): Boolean = lifespan > bird.lifespan
fixed species: String
}

class Osprey extends Bird {
fixed species: "Pandion haliaetus"
}

typealias Adult = Bird(lifespan >= 2)

function Infant(_name: String): Bird = new { name = _name; lifespan = 0 }

pigeon: Bird = new {
name = "Pigeon"
}

@Deprecated { message = "Replace with \(pigeonName)" }
oldPigeonName: String

class Project {
local emailAddress = (str) -> str.matches(Regex(#".+@.+"#))
// constrain the nullable type's element type
type: String(contains("source"))?
// constrain the map type and its key/value types
contacts: Map<String(!isEmpty), String(emailAddress)>(length <= 5)
}

project: Project = new {
contacts = Map("Pigeon", "pigeon@example.com")
}


// Mixins
withDietTyped = new Mixin<Bird> {
diet = "Seeds"
}

// Generators

parrot {
lifespan = 20
for (_name in names) {
new {
name = _name
lifespan = 42
}
}
when (isSinger) {
idol = "Aretha Franklin"
} else {
idol = "Wolfgang Amadeus Mozart"
}
}


// Let bindings
name = let (_ = trace("defining name")) "Eagle"


// Spreading
entries1 {
["Pigeon"] = "Piggy the Pigeon"
}

entries2 {
...entries1
}

// Member Predicates
environmentVariables {
new { name = "PARROT"; value = "parrot-value" }
}

updated = (environmentVariables) {
[[name == "PARROT"]] {
value = "new-value"
}
}

/// Doc comments
// showing amending
woodPigeon (parrot) {
name = "Common wood pigeon"
taxonomy {
`class` = "Aves"
}
}

// Transforming objects
res = woodPigeon
.toMap()
.remove("name")

Loading
Loading