Skip to content
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
32 changes: 32 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ command-group = "5.0.1"
flate2 = "1.1.5"
humantime = "2.3.0"
lsp-types = "0.97.0"
lzma-rs = "0.3.0"
regex = "1.11.1"
reqwest = { version = "0.12.24", default-features = false, features = ["blocking", "json", "rustls-tls"] }
serde = { version = "1.0.228", features = ["derive"] }
Expand Down
21 changes: 20 additions & 1 deletion activate.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
# Source this from the repo root to put the tools installed by `make download-dev-env`
# (go, java, node, dotnet) on PATH: `source activate.sh`
# (go, java, node, dotnet, zig, ruby) on PATH: `source activate.sh`
case ":$PATH:" in
*":$PWD/.env/bin:"*) ;;
*) export PATH="$PWD/.env/bin:$PATH" ;;
esac

# ruby-builder's prebuilt ruby needs its lib dir on LD_LIBRARY_PATH (RUNPATH points at the
# hosted-toolcache path it was built for) and RUBYLIB (default $LOAD_PATH is baked in too).
if [[ -d "$PWD/.env/ruby/lib" ]]; then
export LD_LIBRARY_PATH="$PWD/.env/ruby/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
rubylib_entries=()
for dir in "$PWD"/.env/ruby/lib/ruby/*/; do
[[ -d "$dir" ]] || continue
rubylib_entries+=("${dir%/}")
for arch_dir in "$dir"*linux*/; do
[[ -d "$arch_dir" ]] && rubylib_entries+=("${arch_dir%/}")
done
done
if (( ${#rubylib_entries[@]} > 0 )); then
rubylib_joined=$(IFS=:; echo "${rubylib_entries[*]}")
export RUBYLIB="$rubylib_joined${RUBYLIB:+:$RUBYLIB}"
fi
unset rubylib_entries rubylib_joined dir arch_dir
fi
2 changes: 1 addition & 1 deletion data
Submodule data updated 1 files
+10 −0 lsp-cli.yaml
16 changes: 16 additions & 0 deletions playground/clojure/main.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(ns main)

(defrecord OrderItem [name quantity price])

(defrecord Order [customer items])

(defn order-total [order]
(reduce + (map (fn [item] (* (:quantity item) (:price item))) (:items order))))

(defn build-sample-order []
(->Order "Carol" [(->OrderItem "Mouse" 1 35.0) (->OrderItem "Pad" 1 12.5)]))

(defn format-order [order]
(str (:customer order) " has " (count (:items order)) " items worth " (order-total order)))

(println (format-order (build-sample-order)))
35 changes: 35 additions & 0 deletions playground/luau/main.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
type OrderItem = {
name: string,
quantity: number,
price: number,
}

type Order = {
customer: string,
items: { OrderItem },
}

local function order_total(order: Order): number
local sum = 0
for _, item in order.items do
sum += item.quantity * item.price
end
return sum
end

local function build_sample_order(): Order
return {
customer = "Carol",
items = {
{ name = "Mouse", quantity = 1, price = 35.0 },
{ name = "Pad", quantity = 1, price = 12.5 },
},
}
end

local function format_order(order: Order): string
return string.format("%s has %d items worth %.2f", order.customer, #order.items, order_total(order))
end

local order = build_sample_order()
print(format_order(order))
42 changes: 42 additions & 0 deletions playground/odin/main.odin
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import "core:fmt"

OrderItem :: struct {
name: string,
quantity: int,
price: f64,
}

Order :: struct {
customer: string,
items: []OrderItem,
}

order_total :: proc(order: Order) -> f64 {
sum := 0.0
for item in order.items {
sum += f64(item.quantity) * item.price
}
return sum
}

build_sample_order :: proc() -> Order {
return Order{
customer = "Carol",
items = []OrderItem{
{name = "Mouse", quantity = 1, price = 35.0},
{name = "Pad", quantity = 1, price = 12.5},
},
}
}

format_order :: proc(order: Order) -> string {
total := order_total(order)
return fmt.tprintf("%s has %d items worth %.2f", order.customer, len(order.items), total)
}

main :: proc() {
order := build_sample_order()
fmt.println(format_order(order))
}
18 changes: 18 additions & 0 deletions playground/perl/lib/Order.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package Order;

use strict;
use warnings;

sub new {
my ($class, $customer, $items) = @_;
return bless { customer => $customer, items => $items }, $class;
}

sub total {
my ($self) = @_;
my $sum = 0;
$sum += $_->{quantity} * $_->{price} for @{ $self->{items} };
return $sum;
}

1;
11 changes: 11 additions & 0 deletions playground/perl/lib/OrderItem.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package OrderItem;

use strict;
use warnings;

sub new {
my ($class, $name, $quantity, $price) = @_;
return bless { name => $name, quantity => $quantity, price => $price }, $class;
}

1;
18 changes: 18 additions & 0 deletions playground/perl/lib/Report.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package Report;

use strict;
use warnings;
use Exporter qw(import);

our @EXPORT_OK = qw(format_order);

sub format_order {
my ($order) = @_;
my $count = scalar @{ $order->{items} };
return sprintf(
"%s has %d items worth %.2f",
$order->{customer}, $count, $order->total
);
}

1;
17 changes: 17 additions & 0 deletions playground/perl/main.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use strict;
use warnings;
use lib 'lib';
use Order;
use OrderItem;
use Report qw(format_order);

sub build_sample_order {
my @items = (
OrderItem->new("Mouse", 1, 35.0),
OrderItem->new("Pad", 1, 12.5),
);
return Order->new("Carol", \@items);
}

my $order = build_sample_order();
print format_order($order), "\n";
3 changes: 3 additions & 0 deletions playground/ruby/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source "https://rubygems.org"

ruby ">= 3.0"
36 changes: 36 additions & 0 deletions playground/ruby/lib/order.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class OrderItem
attr_reader :name, :quantity, :price

def initialize(name, quantity, price)
@name = name
@quantity = quantity
@price = price
end

def total
quantity * price
end
end

class Order
attr_reader :customer, :items

def initialize(customer, items)
@customer = customer
@items = items
end

def total
items.sum(&:total)
end
end

def build_sample_order
Order.new(
"Carol",
[
OrderItem.new("Mouse", 1, 35.0),
OrderItem.new("Pad", 1, 12.5)
]
)
end
3 changes: 3 additions & 0 deletions playground/ruby/lib/report.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def format_order(order)
"#{order.customer} has #{order.items.length} items worth #{format('%.2f', order.total)}"
end
5 changes: 5 additions & 0 deletions playground/ruby/main.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require_relative "lib/order"
require_relative "lib/report"

order = build_sample_order
puts format_order(order)
14 changes: 14 additions & 0 deletions playground/vim/main.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function! OrderTotal(quantity, price)
return a:quantity * a:price
endfunction

function! BuildSampleOrder()
return "Carol"
endfunction

function! FormatOrder(customer, quantity, price)
let total = OrderTotal(a:quantity, a:price)
return a:customer . " has " . a:quantity . " items worth " . total
endfunction

echo FormatOrder(BuildSampleOrder(), 2, 35.0)
16 changes: 16 additions & 0 deletions playground/zig/build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const std = @import("std");

pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

const exe = b.addExecutable(.{
.name = "playground",
.root_module = b.createModule(.{
.root_source_file = b.path("main.zig"),
.target = target,
.optimize = optimize,
}),
});
b.installArtifact(exe);
}
49 changes: 49 additions & 0 deletions playground/zig/main.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const std = @import("std");

const OrderItem = struct {
name: []const u8,
quantity: u32,
price: f64,

fn total(self: OrderItem) f64 {
return @as(f64, @floatFromInt(self.quantity)) * self.price;
}
};

const Order = struct {
customer: []const u8,
items: []const OrderItem,

fn total(self: Order) f64 {
var sum: f64 = 0;
for (self.items) |item| {
sum += item.total();
}
return sum;
}
};

fn sample_order() Order {
return Order{
.customer = "Carol",
.items = &[_]OrderItem{
OrderItem{ .name = "Mouse", .quantity = 1, .price = 35.0 },
OrderItem{ .name = "Pad", .quantity = 1, .price = 12.5 },
},
};
}

fn format_order(order: Order, buffer: []u8) ![]u8 {
return std.fmt.bufPrint(buffer, "{s} has {d} items worth {d:.2}", .{
order.customer,
order.items.len,
order.total(),
});
}

pub fn main() !void {
const order = sample_order();
var buffer: [128]u8 = undefined;
const report = try format_order(order, &buffer);
std.debug.print("{s}\n", .{report});
}
Loading