Skip to content
Open
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
13 changes: 13 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// A launch configuration that launches the extension inside a new window
{
"version": "0.1.0",
"configurations": [
{
"name": "Launch Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ]
}
]
}
113 changes: 110 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,114 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [1.6.1] - 2018-06-12

- Fix links in README

## [1.6.0] - 2018-06-12

- Update for Unicode identifiers. You should be able to use unicode anywhere it's legal now and have it be correctly colored. #84
- Fix bug with multiple expressions in parentheses. #46
- Fix comments inside locals, and fix comments inside globals used with `${...}`. #90
- Color macros better in list extended function. #75
- Allow macros within subscripts. #74 and #57
- Make comment highlighting stubbornly accurate. See [this Statalist post](https://www.statalist.org/forums/forum/general-stata-discussion/general/1448244-understanding-stata-s-comment-hierarchy) for more information about how Stata highlights in practice, and [go here for an example](examples/comments.md).
- Add note to README that language-latex and language-markdown must be installed for dynamic documents syntax highlighting to work
- Update to highlight dynamic documents in Markdown and LaTeX
- Add highlighting for Python-like docstrings in block comments
- Don't alert for error around braces (`{}`) inside function calls

- Add support for factor variables. Fixes #70
- Fix coloring for macro functions that take multiple new macros as arguments, i.e. `tempvar`, `tempfile`, and `tempname`. Fixes #71
- Add regex functions to autocomplete. Fixes #69
- Alert when variable labels are >80 characters. Fixes #72

## [1.2.8] - 2017-11-28
- Fix syntax command. Fixes #61
- Add some user-written commands. Fixes #64

## [1.2.7] - 2017-11-20
- allow there to be no spaces before = in gen command. Fixes https://github.com/kylebarron/language-stata/issues/59.

## [1.2.6] - 2017-11-18
- No changes

## [1.2.5] - 2017-11-18
- allow /* to start a comment block anywhere, not just after whitespace. Fixes https://github.com/kylebarron/language-stata/issues/55

## [1.2.4] - 2017-11-18
- Fix `gen` command
- Fix global macro coloring when using `\` as a path delimiter in strings. (i.e. `"$datadir\file.dta"`). Fixes [#52](https://github.com/kylebarron/language-stata/issues/52).
- Allow for markdown code block in strings to not apply "macro" tags in specific situations. Allows e.g. `di "```stata"` as long as there's no `'` character in the text. Fixes [#53](https://github.com/kylebarron/language-stata/issues/53).

## [1.2.3] - 2017-11-11
- Fix bugs created in 1.2.1
- Namely, fix the list of macro reserved names

## [1.2.2] - 2017-11-11
- Fix bugs created in 1.2.1

## [1.2.1] - 2017-11-10
- Fix macro extended function bugs
- Add macro checking to `foreach` and `syntax`
- Restore name checking to `gen`
- Fix bug for brackets before comma in the `syntax` command
- Add `\` as an operator for use with matrices
- Allow functions to be embedded within subscripts

## [1.2.0] - 2017-11-03
- Color SQL queries used in the `odbc` command. (The `language-sql` base package must be active.)
- Regex bug fixes and enhancements:
- Color parentheses forming capture groups
- In regular `regexm()`, color as illegal any group starting with `*`, `?`, or `+`.
- Color lookaheads and lookbehinds in `ustrregexm()`
- Fix highlighting of enclosed functions in `regexm()` and `ustrregexm()`
- Standardize highlighting for `regress` and other "model commands". (Had been colored as _functions_, should be colored as _commands_.)

## [1.1.2] - 2017-10-12
- Color `==` as illegal in `replace var == 0`
- Fix `log` coloring so that `filename.log` isn't colored
- Bugfixes with `drop` and `keep` commands
- Allow embedded macros in extended macro functions
- Miscellaneous bugs fixed by adding `\\b` so that something like `if_yes` doesn't color `if`

## [1.1.1] - 2017-10-11
- Fixed bug where, e.g. only `label vari` was colored of `label variable ...`. There were many instances of code that could have been affected that were fixed.

## [1.1.0] - 2017-10-11
- Improved `syntax` command to correctly color across multiple lines. Solves https://github.com/kylebarron/language-stata/issues/19
- Colors extended macro functions inside local macros as well as during macro instantiation.
- Allow macros in `forvalues` loop statement, like ``forval i = `start_num' / `end_num' {``
- Allow for local and global macros within regular expression match strings
- Color `_all` as a constant
- Include Mata functions from old [atom-language-stata](https://github.com/benwhalley/atom-language-stata) package
- `drop` and `keep` alert you if you type `drop varlist if` or `drop varlist in`. (It's only legal to use `if` or `in` without a _varlist_).

## [1.0.4] - 2017-10-02
- Fix highlighting for global macro with braces inside loop
- Now the `}` line can only be colored as error if there's text on that line and if there's at least one space before the `}`.
- Remove some deprecated functions
- Turn off docblockr tag if appears immediately after word character
- Show error for `gen var == 5`

## [1.0.3] - 2017-10-02
- Fix comment bug created in 1.0.2.
- Disallow star-comments inside block-comments

## [1.0.2] - 2017-10-02
- Fix bug to allow nested comment blocks
- Fix docblockr tag coloring

## [1.0.1] - 2017-10-01
- Fix `*regexr*()` functions to color regex before typing the second comma

## [1.0.0] - 2017-09-30
### Added
- Unicode regex support. This includes support for the entire (or at least most) of the ICU regex engine.
- Colors invalid escapes as illegal in the standard regex parser, like \w or \s.

### Fixed
- color regex functions within other functions
- Don't color as illegal the {} within the `spacebef` and `spaceaft` functions in the outreg package.

## [0.5.16] - 2017-09-22
### Added
Expand All @@ -17,3 +123,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed
- Regex highlighting error that colored capturing groups wrong
-
70 changes: 54 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,79 @@
# Stata language support in Atom
[![Installs!](https://img.shields.io/apm/dm/language-stata.svg?style=flat-square)](https://atom.io/packages/language-stata)
[![Version!](https://img.shields.io/apm/v/language-stata.svg?style=flat-square)](https://atom.io/packages/language-stata)
[![License](https://img.shields.io/apm/l/language-stata.svg?style=flat-square)](https://github.com/kylebarron/language-stata/blob/master/LICENSE)

# Stata language support in Visual Studio Code
[![GitHub stars](https://img.shields.io/github/stars/kylebarron/language-stata.svg?style=social&label=Star)](https://github.com/kylebarron/language-stata)
[![GitHub forks](https://img.shields.io/github/forks/kylebarron/language-stata.svg?style=social&label=Fork)](https://github.com/kylebarron/language-stata)

#### Stata syntax highlighting in Atom, built from the ground up.
#### Stata syntax highlighting in Visual Studio Code, built from the ground up.
Also [available for Atom](https://github.com/kylebarron/language-stata).

![stata](./img/stata-vscode.png)
Code snippet from [Gtools](https://github.com/mcaceresb/stata-gtools), a faster implementation of Stata's collapse and egen using C plugins. Shown with the [Material](https://marketplace.visualstudio.com/items?itemName=Equinusocio.vsc-material-theme) theme.

Note: This is a new package that replaces the [previous](https://github.com/benwhalley/atom-language-stata) syntax highlighter. Please add [issues](https://github.com/kylebarron/language-stata/issues) for any bugs, comments, or suggestions.

## Features

This package highlights:
- System commands, functions, and function arguments
- Macros, both global and local
- Accurately colors nested macros and escaped macros in strings when you want the inner macro to evaluate at runtime
- Colors macro extended functions inside `` `: ... '`` as well as after `local lname:`
- Comments, [more accurately than Stata's Do-file Editor](examples/comments.md).
- Regular expressions
- Colors both the limited syntax provided through the `regexr()` and `regexm()` functions, as well as the vastly expanded regex syntax provided in Stata 14 and 15 through the `ustrregexm()`, `ustrregexrf()`, and `ustrregexra()` functions.
- Dynamic Markdown and LaTeX documents. [Instructions below.](#dynamic-documents)

Other nice features:
- Autocomplete for built-in commands and functions, and for your macros as you write them.
- Works with unicode identifiers. Use unicode anywhere it's legal Stata syntax.
- Alerts you if your variable name is illegal, i.e. if your variable name is more than 32 chars, starts with a number, or is a reserved name.
- Alerts you if you have any text other than } on a line ending a foreach/forvalues/if/else command
- Local macro back tick autocompletion. When you write a `, Atom automatically fills in a ' after your cursor
- Local macro back tick autocompletion. When you write a `, Visual Studio Code automatically fills in a ' after your cursor
- Makes it easy to spot incorrect nesting of compound quotes
- Support for programming ligatures for all valid Stata syntax for fonts that support them, like the [Fira Code](https://github.com/tonsky/FiraCode) font.
- Highlights [Docblockr](https://atom.io/packages/docblockr)-style keywords inside comments (anything like `@Note`)
- Highlights SQL queries used in the odbc command. (The language-sql base package must be active.)

#### Note
Some themes may not color all parts of the syntax.

## Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
```
ext install stata-enhanced
```

To install, do one of the following:
- Go to Preferences/Settings > Install > Packages; and then search for "language-stata-plus"
- At the command line, type `apm install language-stata-plus`
## Running Code

The local macro back tick autocompletion won't function until you fully restart Atom. Do `ctrl-shift-P` or `cmd-shift-P` to bring up the command palette, type `Window: Reload`, and click enter.
This package doesn't have the capabilities to run your code in Stata. If you're using Linux, you can use my [scripts](https://github.com/kylebarron/stata-autokey) with the [Autokey](https://github.com/autokey-py3/autokey) automation utility to quickly run selections of your files in a graphical session of Stata.

## Running Code
You might also be interested in trying to port Atom's `stata-exec` package.

## Dynamic Documents

![](img/dyntext_domd.png)

Stata 15 brought new features for working with dynamic documents. The [`dyndoc`](https://www.stata.com/help.cgi?dyndoc) command lets you write in Markdown and converts your file and code to HTML for viewing in a web browser.

It also added the [`dyntext`](https://www.stata.com/help.cgi?dyntext) command, which fills in Stata output for any text file, without touching the text itself. This lets you then use third-party document generators like [Pandoc](https://pandoc.org/) and [LaTeX](https://www.latex-project.org/) to generate documents.

This package now provides syntax highlighting for Stata code written inside Stata's [dynamic tags](https://www.stata.com/help.cgi?dynamic+tags) for Markdown and LaTeX documents.

By default, this package's Markdown and LaTeX syntax highlighting will be applied for files ending in `.domd` and `.dotex` respectively. **The [Markdown All in One](https://marketplace.visualstudio.com/items?itemName=yzhang.markdown-all-in-one) and [LaTeX Workshop](https://marketplace.visualstudio.com/items?itemName=James-Yu.latex-workshop) packages must be installed for the highlighting to work.**

If you name your file with a different extension, you can manually set the highlighting by clicking on the "Plain Text" button on the bottom right of the screen (or by pressing <kbd>CTRL</kbd>+<kbd>SHIFT</kbd>+<kbd>L</kbd>) and then selecting `Stata Dyndoc (Markdown)` or `Stata Dyndoc (LaTeX)` from the drop-down menu.

### Examples

An example of the PDF output of using `dyntext` and Pandoc is in the examples folder: [`dyntext.pdf`](examples/dyntext.pdf).

That file was created by running

```stata
dyntext dyntext.domd, saving(dyntext.md) replace
```
from inside Stata 15, and then with

```
pandoc dyntext.md -o dyntext.pdf
```

Check out the `script` or `stata-exec` packages. If you're using Linux, you can use my [scripts](https://github.com/kylebarron/stata-autokey) with the [Autokey](https://github.com/autokey-py3/autokey) automation utility to quickly run selections of your files in a graphical session of Stata.
on the command line using [Pandoc](https://pandoc.org/).

The file [`dyntext.dotex`](examples/dyntext.dotex) is a proof-of-concept and should compile with LaTeX but the output is not shown here.
33 changes: 33 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Examples

## Comments

See [comments.md](comments.md) for information on how Stata deals with comments.

## Dynamic Documents

The file [`dyntext.pdf`](dyntext.pdf) in this folder was created with

```stata
dyntext dyntext.domd, saving(dyntext.md) replace
```

from inside Stata 15, and then with

```
pandoc dyntext.md -o dyntext.pdf
```

on the command line using [Pandoc](https://pandoc.org/).

The file [`dyntext.dotex`](dyntext.dotex) is a proof-of-concept and should compile with LaTeX but the output is not shown here.

---

#### `dyntext.domd`:

![](../img/dyntext_domd.png)

#### `dyntext.dotex`:

![](../img/dyntext_dotex.png)
47 changes: 47 additions & 0 deletions examples/comments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Accurate comment highlighting

The intricates of Stata's comment syntax highlighting were brought to my attention by [this Statalist post](https://www.statalist.org/forums/forum/general-stata-discussion/general/1448244-understanding-stata-s-comment-hierarchy).

This package now highlights comments more accurately than the Stata Do-file Editor. This way you'll know exactly which parts of your do-file will actually run.

VS Code highlighter:
![](../img/comments-example-vscode.png)

Dofile Editor:
![](../img/comments-example-doeditor.png)

Stata output (with Stata SE 15.1)
![](../img/comments-example-output.png)

Here's the example text.

```stata
* /* This will be a multi-line comment
disp "Not printed"
*/

* // /* Ignored due to inline comment
disp "Printed 1"

// /* Also ignored due to inline comment
disp "Printed 2"

*// /* This is not an inline comment, so this is multi-line again
disp "Not printed"
*/

* ///
disp "Not printed. Line continuation applies"

* line continuation ///
///
disp "Not printed. Line continuation applies"

// /// Line continuation ignored due to inline comment
disp "Printed 3"

/*
/* Nested */
disp "Not printed"
*/* disp "Not printed"
```
Loading