Skip to content

Commit

Permalink
Vscode [Now publishing] (dataform-co#989)
Browse files Browse the repository at this point in the history
* prep for packaging

* Add a hacky packager rule

* Add license and README

* Clean up the package a bit

* Version update and command change

* Fix a bug with finding definitions such that only the ref contents are highlighted when you cmd + hover over it

* Update version

* Delete package again

* Updated instructions for publish as cli ain't working

* LICENSE and README included

* Minor package changes:]

Co-authored-by: Lewis Hemens <[email protected]>
  • Loading branch information
George McGowan and lewish authored Sep 14, 2020
1 parent ca4ce6e commit 3edd50b
Show file tree
Hide file tree
Showing 10 changed files with 325 additions and 29 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
"untildify": "^4.0.0",
"uuid": "^7.0.2",
"vm2": "^3.9.2",
"vsce": "^1.79.5",
"vscode-languageclient": "^6.1.3",
"vscode-languageserver": "^6.1.1",
"vscode-languageserver-textdocument": "^1.0.1",
Expand Down
14 changes: 14 additions & 0 deletions vscode/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,17 @@ sh_binary(
":vscode-sources",
],
)

sh_binary(
name = "packager",
srcs = ["packager.sh"],
data = [
":language-configuration.json",
":dataform_logo.png",
":package.json",
":README.md",
":LICENSE",
":sqlx.grammar.json",
":vscode-sources",
],
)
21 changes: 21 additions & 0 deletions vscode/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Tada Science Inc

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
10 changes: 7 additions & 3 deletions vscode/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
** Under construction **
## This extension is in Alpha

To run you need vscode and bazel installed. Then run: `bazel run vscode:bin -- /path/to/dataform-repo`
To run this extension you will need the dataform cli installed globally: `npm i -g @dataform/cli`.

This will open a vscode instance in developer mode. Go to a `.sqlx` file to use the extension.
Includes:

- Syntax highlighting for `.sqlx` files
- Realtime compilation of your project
- `cmd + click` on a `ref()` function to go to the file that it references
13 changes: 13 additions & 0 deletions vscode/contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
There are two routes to publishing new versions:

### Web (actually working):

- In the main repo run `bazel run vscode:packager /tmp/dataform-package.vsix`
- Take the generated package and upload it [here](https://marketplace.visualstudio.com/manage/publishers/dataform)

### CLI (not working right now)

- In the main repo run `bazel run vscode:packager /tmp/dataform-package.vsix`
- Then take the package and paste it into this directory
- Then run `vsce publish`
- Currently this doesn't work as `vsce publish` will try to publish typescript files
Binary file added vscode/dataform_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 19 additions & 4 deletions vscode/package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
{
"name": "dataform",
"version": "0.0.1",
"categories": [
"Programming Languages"
],
"description": "Syntax highlighting, compilation, and intellisense for Dataform and SQLX projects.",
"displayName": "Dataform",
"publisher": "dataform",
"version": "0.0.9",
"icon": "dataform_logo.png",
"repository": {
"url": "https://github.com/dataform-co/dataform/tree/master/vscode"
},
"engines": {
"vscode": "^1.45.0"
"vscode": "^1.48.0"
},
"activationEvents": [
"workspaceContains:**/*.sqlx"
],
"main": "extension.js",
"dependencies": {
"vscode-languageclient": "^6.1.3",
"vscode-languageserver": "^6.1.1",
"vscode-languageserver-textdocument": "^1.0.1"
},
"contributes": {
"commands": [
{
"command": "dataform.compile",
"title": "Recompile dataform",
"category": "cli"
"title": "Compile project",
"category": "Dataform"
}
],
"languages": [
Expand Down
3 changes: 3 additions & 0 deletions vscode/packager.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cd vscode
npm i
npx vsce package --out $@
26 changes: 17 additions & 9 deletions vscode/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,23 @@ connection.onDefinition(
if (!refContents || refContents.length === 0) {
return null;
}
const linkedFileName = retrieveLinkedFileName(refContents.join(""));
const fileString = `${WORKSPACE_ROOT_FOLDER}/${linkedFileName}`;
return {
uri: fileString,
range: {
start: { line: 0, character: 0 },
end: { line: 1, character: 0 }
}
} as Location;

const minPosition = lineWithRef.search(refRegex);
const refStatement = refContents[0];
const maxPosition = minPosition + refStatement.length;

if (params.position.character > minPosition && params.position.character < maxPosition) {
// TODO: Make this work for multiple refs in one line
const linkedFileName = retrieveLinkedFileName(refContents[0]);
const fileString = `${WORKSPACE_ROOT_FOLDER}/${linkedFileName}`;
return {
uri: fileString,
range: {
start: { line: 0, character: 0 },
end: { line: 1, character: 0 }
}
} as Location;
}
}
);

Expand Down
Loading

0 comments on commit 3edd50b

Please sign in to comment.