Skip to content

Commit

Permalink
Initial working commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ReinisSprogis committed Mar 19, 2023
0 parents commit 4797a95
Show file tree
Hide file tree
Showing 13 changed files with 1,063 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Set default behavior to automatically normalize line endings.
* text=auto
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
*.vsix
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// A launch configuration that launches the extension inside a new window
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [
{
"name": "Marlin",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
]
}
]
}
4 changes: 4 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.vscode/**
.vscode-test/**
.gitignore
vsc-extension-quickstart.md
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Change Log

All notable changes to the "marlin" extension will be documented in this file.

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [Unreleased]

- Initial release
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# marlin README

This is the README for your extension "marlin". After writing up a brief description, we recommend including the following sections.

## Features

Describe specific features of your extension including screenshots of your extension in action. Image paths are relative to this README file.

For example if there is an image subfolder under your extension project workspace:

\!\[feature X\]\(images/feature-x.png\)

> 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.
## Requirements

If you have any requirements or dependencies, add a section describing those and how to install and configure them.

## Extension Settings

Include if your extension adds any VS Code settings through the `contributes.configuration` extension point.

For example:

This extension contributes the following settings:

* `myExtension.enable`: Enable/disable this extension.
* `myExtension.thing`: Set to `blah` to do something.

## Known Issues

Calling out known issues can help limit users opening duplicate issues against your extension.

## Release Notes

Users appreciate release notes as you update your extension.

### 1.0.0

Initial release of ...

### 1.0.1

Fixed issue #.

### 1.1.0

Added features X, Y, and Z.

---

## Working with Markdown

You can author your README using Visual Studio Code. Here are some useful editor keyboard shortcuts:

* Split the editor (`Cmd+\` on macOS or `Ctrl+\` on Windows and Linux).
* Toggle preview (`Shift+Cmd+V` on macOS or `Shift+Ctrl+V` on Windows and Linux).
* Press `Ctrl+Space` (Windows, Linux, macOS) to see a list of Markdown snippets.

## For more information

* [Visual Studio Code's Markdown Support](http://code.visualstudio.com/docs/languages/markdown)
* [Markdown Syntax Reference](https://help.github.com/articles/markdown-basics/)

**Enjoy!**
10 changes: 10 additions & 0 deletions extension.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const vscode = require('vscode');
const {hoverInfoActivate} = require('./hover');
function activate(context) {
console.log('Congratulations, your extension "extension" is now active!');
hoverInfoActivate(context);


}

exports.activate = activate;
138 changes: 138 additions & 0 deletions hover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
const vscode = require('vscode');
const axios = require('axios');
const cheerio = require('cheerio');
const path = require('path');

//This function provides information on hovering over keywords
function hoverInfoActivate(context) {
console.log('hoverInfoActivate is activated!');
const keywords = [
'G01', 'G1', 'G001'
];

const hoverProvider = vscode.languages.registerHoverProvider('marlin', {
provideHover(document, position, token) {
const range = document.getWordRangeAtPosition(position);
const word = document.getText(range);
const baseURL = "https://marlinfw.org";
const relativeUrlRegex = /<a href="(\/.*?)">/g;
console.log("Word: " + word);

//If the word is G0 or G00 or G1 or G01 or G001
//Then return the G0/G1 page
//This is because the G0/G1 page contains information on both G0 and G1
//Linear movement commands
if (word == 'G0' || word == 'G00' || word == 'G1' || word == 'G01' || word == 'G001') {
console.log("G0/G1")
return axios.get('https://marlinfw.org/docs/gcode/G000-G001.html')
.then(response => {
const data = cheerio.load(response.data);
const content = data('div.col-lg-12.row.long').html();

console.log("Content g1: " + content);
const updatedMarkdownContent = content.toString().replace(relativeUrlRegex, `<a href="${baseURL}$1">`);
const markdownString = new vscode.MarkdownString('' + updatedMarkdownContent, true);
markdownString.supportHtml = true;
return new vscode.Hover(markdownString);
})
.catch(error => {
console.error(error);
});

} else if (word == 'G2' || word == 'G3' || word == 'G02' || word == 'G03' || word == 'G002' || word == 'G003') {
//If the word is G2 or G3 or G02 or G03 or G002 or G003
//Then return the G2/G3 page
//This is because the G2/G3 page contains information on both G2 and G3
//Circular movement commands


return axios.get('https://marlinfw.org/docs/gcode/G002-G003.html')
.then(response => {
const data = cheerio.load(response.data);
const content = data('div.col-lg-12.row.long').html();

console.log("Content g2: " + content);
const markdownString = new vscode.MarkdownString('' + content.toString(), true);
markdownString.supportHtml = true;
return new vscode.Hover(markdownString);
})
.catch(error => {
console.error(error);
});
} else if (word == 'G17' || word == 'G18' || word == 'G19' || word == 'G017' || word == 'G018' || word == 'G019') {
//If the word is G17, G18, G19, G017, G018, G019
//Then return the G17/G19 page
//This is because the G17/G19 page contains information on both G17 and G19
//Plane selection commands
return axios.get('https://marlinfw.org/docs/gcode/G017-G019.html')
.then(response => {
const data = cheerio.load(response.data);
const content = data('div.col-lg-12.row.long').html();
console.log("Content g17: " + content);
const markdownString = new vscode.MarkdownString('' + content.toString(), true);
markdownString.supportHtml = true;
return new vscode.Hover(markdownString);
})
}
else if(word == 'G54' || word == 'G55' || word == 'G56' || word == 'G57' || word == 'G58'|| word == 'G59' || word == 'G054' || word == 'G055' || word == 'G056' || word == 'G057' || word == 'G058'|| word == 'G059'){
//If the word is G54, G55, G56, G57, G58, G59, G054, G055, G056, G057, G058, G059
//Then return the G54/G59 page
//This is because the G54/G59 page contains information on both G54 and G59
//Coordinate system selection commands
return axios.get('https://marlinfw.org/docs/gcode/G054-G059.html')
.then(response => {
const data = cheerio.load(response.data);
const content = data('div.col-lg-12.row.long').html();
console.log("Content g54: " + content);
const markdownString = new vscode.MarkdownString('' + content.toString(), true);
markdownString.supportHtml = true;
return new vscode.Hover(markdownString);
})


}
else {

//If G or M value contains 1 or 2 digits, add the 0 at the beginning to match 3 digit format.
//G1 -> G001
//G01 -> G001
//G001 -> G001
//M1 -> M001
//M01 -> M001
//M001 -> M001
filtered = '';
if (word[0] == 'G' || word[0] == 'M' && word.length <= 3) {
if (word.length == 2) {
filtered = word[0] + '00' + word.substring(1);
} else if (word.length == 3) {
filtered = word[0] + '0' + word.slice(1);
} else {
filtered = word;
}
} else {
filtered = word;
}

console.log("Filtered: " + filtered);
return axios.get('https://marlinfw.org/docs/gcode/' + filtered + '.html')
.then(response => {
const data = cheerio.load(response.data);
const content = data('div.col-lg-12.row.long').html();

console.log("Content: " + content);
const markdownString = new vscode.MarkdownString('' + content.toString(), true);
markdownString.supportHtml = true;
return new vscode.Hover(markdownString);
})
.catch(error => {
console.error(error);
});
}
}
});

context.subscriptions.push(hoverProvider);
}


exports.hoverInfoActivate = hoverInfoActivate;
30 changes: 30 additions & 0 deletions language-configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"comments": {
// symbol used for single line comment. Remove this entry if your language does not support line comments
"lineComment": "//",
// symbols used for start and end a block comment. Remove this entry if your language does not support block comments
"blockComment": [ "/*", "*/" ]
},
// symbols used as brackets
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"]
],
// symbols that are auto closed when typing
"autoClosingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"]
],
// symbols that can be used to surround a selection
"surroundingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"]
]
}
Loading

0 comments on commit 4797a95

Please sign in to comment.