Skip to content

Commit b9ac795

Browse files
committed
init
0 parents  commit b9ac795

10 files changed

+305
-0
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Set default behavior to automatically normalize line endings.
2+
* text=auto

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
*.vsix

.vscode/launch.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// A launch configuration that launches the extension inside a new window
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
{
6+
"version": "0.2.0",
7+
"configurations": [
8+
{
9+
"name": "Extension",
10+
"type": "extensionHost",
11+
"request": "launch",
12+
"args": [
13+
"--extensionDevelopmentPath=${workspaceFolder}"
14+
]
15+
}
16+
]
17+
}

.vscodeignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.vscode/**
2+
.vscode-test/**
3+
.gitignore
4+
vsc-extension-quickstart.md

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Change Log
2+
3+
All notable changes to the "source-lsp" extension will be documented in this file.
4+
5+
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
6+
7+
## [Unreleased]
8+
9+
- Initial release

README.md

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# source-lsp README
2+
3+
This is the README for your extension "source-lsp". After writing up a brief description, we recommend including the following sections.
4+
5+
## Features
6+
7+
Describe specific features of your extension including screenshots of your extension in action. Image paths are relative to this README file.
8+
9+
For example if there is an image subfolder under your extension project workspace:
10+
11+
\!\[feature X\]\(images/feature-x.png\)
12+
13+
> Tip: Many popular extensions utilize animations. This is an excellent way to show off your extension! We recommend short, focused animations that are easy to follow.
14+
15+
## Requirements
16+
17+
If you have any requirements or dependencies, add a section describing those and how to install and configure them.
18+
19+
## Extension Settings
20+
21+
Include if your extension adds any VS Code settings through the `contributes.configuration` extension point.
22+
23+
For example:
24+
25+
This extension contributes the following settings:
26+
27+
* `myExtension.enable`: Enable/disable this extension.
28+
* `myExtension.thing`: Set to `blah` to do something.
29+
30+
## Known Issues
31+
32+
Calling out known issues can help limit users opening duplicate issues against your extension.
33+
34+
## Release Notes
35+
36+
Users appreciate release notes as you update your extension.
37+
38+
### 1.0.0
39+
40+
Initial release of ...
41+
42+
### 1.0.1
43+
44+
Fixed issue #.
45+
46+
### 1.1.0
47+
48+
Added features X, Y, and Z.
49+
50+
---
51+
52+
## Working with Markdown
53+
54+
You can author your README using Visual Studio Code. Here are some useful editor keyboard shortcuts:
55+
56+
* Split the editor (`Cmd+\` on macOS or `Ctrl+\` on Windows and Linux).
57+
* Toggle preview (`Shift+Cmd+V` on macOS or `Shift+Ctrl+V` on Windows and Linux).
58+
* Press `Ctrl+Space` (Windows, Linux, macOS) to see a list of Markdown snippets.
59+
60+
## For more information
61+
62+
* [Visual Studio Code's Markdown Support](http://code.visualstudio.com/docs/languages/markdown)
63+
* [Markdown Syntax Reference](https://help.github.com/articles/markdown-basics/)
64+
65+
**Enjoy!**

language-configuration.json

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"comments": {
3+
"lineComment": "//",
4+
"blockComment": ["/*", "*/"]
5+
},
6+
"brackets": [
7+
["{", "}"],
8+
["[", "]"],
9+
["(", ")"]
10+
],
11+
"autoClosingPairs": [
12+
{ "open": "{", "close": "}" },
13+
{ "open": "[", "close": "]" },
14+
{ "open": "(", "close": ")" },
15+
{ "open": "'", "close": "'" },
16+
{ "open": "\"", "close": "\"" },
17+
{ "open": "`", "close": "`" }
18+
],
19+
"surroundingPairs": [
20+
{ "open": "{", "close": "}" },
21+
{ "open": "[", "close": "]" },
22+
{ "open": "(", "close": ")" },
23+
{ "open": "'", "close": "'" },
24+
{ "open": "\"", "close": "\"" },
25+
{ "open": "`", "close": "`" }
26+
],
27+
"wordPattern": "-?\\d*\\.\\d\\w*|\\w+",
28+
"indentationRules": {
29+
"increaseIndentPattern": "(\\{[^}\"']*|\\([^\\)]*$|\\[[^\\]]*$)",
30+
"decreaseIndentPattern": "^\\s*[\\}\\]].*$"
31+
},
32+
"onEnterRules": [
33+
{
34+
"beforeText": "^\\s*\\b(if|else|for|while||function)\\b.*\\{\\s*$",
35+
"action": { "indentAction": "Indent" }
36+
},
37+
{
38+
"beforeText": "^\\s*\\{\\s*$",
39+
"action": { "indentAction": "Indent" }
40+
},
41+
{
42+
"beforeText": "^\\s*\\}\\s*$",
43+
"action": { "indentAction": "Outdent" }
44+
}
45+
]
46+
}
47+

package.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "source-lsp",
3+
"displayName": "Source-LSP",
4+
"description": "lsp server for source",
5+
"version": "0.0.1",
6+
"engines": {
7+
"vscode": "^1.96.0"
8+
},
9+
"categories": [
10+
"Programming Languages"
11+
],
12+
"contributes": {
13+
"languages": [{
14+
"id": "sourcejs",
15+
"aliases": ["Source", "sourcejs"],
16+
"extensions": [".sourcejs"],
17+
"configuration": "./language-configuration.json"
18+
}],
19+
"grammars": [{
20+
"language": "sourcejs",
21+
"scopeName": "source.sourcejs",
22+
"path": "./syntaxes/sourcejs.tmLanguage.json"
23+
}]
24+
}
25+
}

syntaxes/sourcejs.tmLanguage.json

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{
2+
"name": "Source", "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
3+
4+
"patterns": [
5+
{ "include": "#comments" },
6+
{ "include": "#strings" },
7+
{ "include": "#numbers" },
8+
{ "include": "#keywords" },
9+
{ "include": "#operators" },
10+
{ "include": "#function-names" }
11+
],
12+
"repository": {
13+
"comments": {
14+
"patterns": [
15+
{
16+
"name": "comment.line.double-slash.sourcejs",
17+
"match": "//.*$"
18+
},
19+
{
20+
"name": "comment.block.sourcejs",
21+
"begin": "/\\*",
22+
"end": "\\*/"
23+
}
24+
]
25+
},
26+
"strings": {
27+
"patterns": [
28+
{
29+
"name": "string.quoted.double.sourcejs",
30+
"begin": "\"",
31+
"end": "\"",
32+
"patterns": [
33+
{ "match": "\\\\.", "name": "constant.character.escape.sourcejs" }
34+
]
35+
},
36+
{
37+
"name": "string.quoted.single.sourcejs",
38+
"begin": "'",
39+
"end": "'",
40+
"patterns": [
41+
{ "match": "\\\\.", "name": "constant.character.escape.sourcejs" }
42+
]
43+
},
44+
{
45+
"name": "string.template.sourcejs",
46+
"begin": "`",
47+
"end": "`",
48+
"patterns": [
49+
{ "match": "\\$\\{[^}]+\\}", "name": "meta.template.expression.sourcejs" }
50+
]
51+
}
52+
]
53+
},
54+
"numbers": {
55+
"patterns": [
56+
{
57+
"name": "constant.numeric.sourcejs",
58+
"match": "\\b(0[xX][0-9a-fA-F]+|0[bB][01]+|0[oO]?[0-7]+|\\d+(\\.\\d+)?([eE][+-]?\\d+)?|true|false)\\b"
59+
}
60+
]
61+
},
62+
"keywords": {
63+
"patterns": [
64+
{
65+
"name": "keyword.control.sourcejs",
66+
"match": "\\b(if|else|for|while|break|continue|return|function|in|let|const|import)\\b"
67+
}
68+
]
69+
},
70+
"operators": {
71+
"patterns": [
72+
{
73+
"name": "keyword.operator.sourcejs",
74+
"match": "(\\+|\\-|\\*|\\/|%|===|!==|>|<|>=|<=|&&|\\|\\||!|=|=>)"
75+
}
76+
]
77+
},
78+
"function-names": {
79+
"patterns": [
80+
{
81+
"name": "entity.name.function.sourcejs",
82+
"match": "\\bfunction\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\b"
83+
}
84+
]
85+
}
86+
},
87+
"scopeName": "source.sourcejs"
88+
}

test.sourcejs

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const data = [[5, 6, 5, 4, 3, 4, 8, 7, 6, 7, 6, 5, 4, 3, 2, 8, 9, 4, 3, 2, 1, 0, 5, 6, 8, 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, 0, 3, 4, 9, 2, 1, 2, 3, 8, 7, 7, 6, 7, 8, 5, 6, 7, 2, 1, 0, 9, 4, 3, 2, 1, 7, 6, 7, 8], [1, 7, 8, 7, 6, 5, 4, 0, 1, 4, 7, 8, 3, 2, 8, 9, 6, 9, 8, 9, 3, 4, 5, 9, 8, 7, 8, 3, 0, 3, 4, 5, 6, 8, 9, 4, 3, 4, 9, 8, 2, 1, 9, 8, 5, 4, 0, 0, 6, 0, 1, 0], [5, 6, 7, 1, 0, 1, 3, 0, 0, 5, 6, 5, 4, 1, 9, 4, 5, 6, 7, 8, 2, 7, 6, 4, 7, 6, 9, 5, 6, 9, 3, 2, 1, 0, 0, 1, 2, 3, 8, 2, 1, 0, 8, 7, 6, 0, 1, 2, 5, 4, 2, 1], [0, 5, 4, 2, 5, 6, 2, 1, 9, 6, 6, 7, 8, 0, 0, 3, 4, 3, 0, 9, 1, 8, 0, 3, 4, 5, 0, 6, 7, 8, 4, 3, 4, 5, 8, 9, 4, 5, 6, 3, 4, 5, 6, 9, 7, 8, 9, 3, 4, 4, 3, 8], [1, 2, 3, 3, 4, 7, 8, 7, 8, 7, 5, 4, 9, 1, 1, 2, 3, 2, 1, 2, 0, 9, 1, 2, 3, 2, 1, 5, 4, 1, 0, 2, 5, 6, 7, 2, 3, 8, 7, 4, 5, 6, 7, 8, 3, 4, 9, 8, 3, 5, 4, 9], [2, 0, 1, 2, 9, 8, 9, 1, 0, 1, 2, 3, 8, 1, 0, 3, 0, 1, 2, 2, 1, 3, 2, 3, 0, 1, 2, 3, 3, 2, 2, 1, 0, 5, 0, 1, 2, 9, 6, 5, 4, 5, 0, 1, 2, 5, 6, 7, 6, 6, 7, 8]];
2+
3+
function find_trailhead(x, y) {
4+
if (data[y][x] === 9) {
5+
let not_visited = true;
6+
for_each(p => {
7+
if (head(p) === x && tail(p) === y) {
8+
not_visited = false;
9+
}
10+
}, visited);
11+
if (not_visited) {
12+
visited = pair(pair(x,y), visited);
13+
return 1;
14+
}
15+
}
16+
17+
let num_trailheads = 0;
18+
if (x !== 0 && data[y][x - 1] - data[y][x] === 1){
19+
num_trailheads = num_trailheads + find_trailhead(x - 1, y);
20+
}
21+
if (y !== 0 && data[y-1][x] - data[y][x] === 1){
22+
num_trailheads = num_trailheads + find_trailhead(x, y - 1);
23+
}
24+
if (x !== array_length(data[0])-1 && data[y][x + 1] - data[y][x] === 1){
25+
num_trailheads = num_trailheads + find_trailhead(x + 1 , y);
26+
}
27+
if (y !== array_length(data)-1 && data[y+1][x] - data[y][x] === 1){
28+
num_trailheads = num_trailheads + find_trailhead(x, y + 1);
29+
}
30+
31+
return num_trailheads;
32+
}
33+
34+
let ans = 0;
35+
let visited = list();
36+
37+
for (let y = 0; y < array_length(data); y=y+1) {
38+
for (let x = 0; x < array_length(data[0]); x=x+1) {
39+
if (data[y][x] === 0) {
40+
ans = ans + find_trailhead(x, y);
41+
visited = list();
42+
}
43+
}
44+
}
45+
46+
display(ans);

0 commit comments

Comments
 (0)