Skip to content

Commit

Permalink
feat: only update extension if version changes
Browse files Browse the repository at this point in the history
  • Loading branch information
harrydowning committed Jul 6, 2024
1 parent df77f69 commit 274100f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

![GitHub](https://img.shields.io/github/license/harrydowning/yaml-embedded-languages?color=forest) ![Visual Studio Marketplace Version (including pre-releases)](https://img.shields.io/visual-studio-marketplace/v/harrydowning.yaml-embedded-languages?color=red) ![Visual Studio Marketplace Downloads](https://img.shields.io/visual-studio-marketplace/d/harrydowning.yaml-embedded-languages?color=rebeccapurple)

## Features [#](#features- 'Features')
## Features

Syntax highlighting within YAML block-scalars for [40+ built-in languages](#built-in-languages- 'Built-In Languages') and the ability to add highlighting for any other language with the [yaml-embedded-languages.include](#extension-settings- 'Extension Settings') configuration setting.

![Example yaml file showing syntax highlighting](https://raw.githubusercontent.com/harrydowning/yaml-embedded-languages/master/images/example.png)

### Built-In Languages [#](#built-in-languages- 'Built-In Languages')
### Built-In Languages
The following list shows all valid identifiers for the built-in languages:
- c
- clojure
Expand Down Expand Up @@ -52,25 +52,25 @@ The following list shows all valid identifiers for the built-in languages:
- xml
- yaml (Yes, YAML within YAML!)

## Requirements [#](#requirements- 'Requirements')
## Requirements

None

## Extension Settings [#](#extension-settings- 'Extension Settings')
## Extension Settings

| Name | Description |
| ---- | ----------- |
| `yaml-embedded-languages.include` | Allows the user to include their own languages by providing an object where each key defines the language identifier with regex and the corresponding value specifies the language TextMate `scopeName`. This can be used to add any other language, which could be from another extension. This also allows the user to override any language identifiers currently used for the built-in languages. |

## Known Issues [#](#known-issues- 'Known Issues')
## Known Issues

See [Issues](https://github.com/harrydowning/yaml-embedded-languages/issues)


## Contribution Notes [#](#contribution-notes- 'Contribution Notes')
## Contribution Notes

See [CONTRIBUTING](CONTRIBUTING.md)

## Release Notes [#](#release-notes- 'Release Notes')
## Release Notes

See [CHANGELOG](CHANGELOG.md)
15 changes: 12 additions & 3 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ const fs = require("fs");
const NAME = "yaml-embedded-languages";
const VERSION = "0.3.2";
const DISPLAY_NAME = "YAML Embedded Languages";
const PUBLISHER = "harrydowning";
const INJECTION_PATH = "./syntaxes/injection.json";
const SCOPE_NAME = `${NAME}.injection`;
const SUB_INCLUDE_CONFIG = "include";
const INCLUDE_CONFIG = `${NAME}.${SUB_INCLUDE_CONFIG}`;
const LANGUAGE_SCOPE_PREFIX = "meta.embedded.inline";
const REPOSITORY_SUFFIX = "block-scalar";
const GLOBAL_STATE_VERSION = "version";

const LANGUAGES = {
c: "source.c",
Expand Down Expand Up @@ -75,7 +77,7 @@ const getPackageJson = (languages) => ({
displayName: DISPLAY_NAME,
description: "Support for syntax highlighting within YAML block-scalars.",
icon: "images/icon.png",
publisher: "harrydowning",
publisher: PUBLISHER,
author: {
name: "Harry Downing",
email: "harry.downing17@gmail.com",
Expand Down Expand Up @@ -131,7 +133,7 @@ const getPatterns = (languages) => {
};

const getRepository = (languages) => {
entries = Object.entries(languages);
const entries = Object.entries(languages);
return Object.fromEntries(
entries.map(([name, scopeName]) => [
`${name}-${REPOSITORY_SUFFIX}`,
Expand Down Expand Up @@ -231,7 +233,14 @@ const updateExtension = () => {
};

const activate = (context) => {
updateExtension();
const extension = vscode.extensions.getExtension(`${PUBLISHER}.${NAME}`);
const currentVersion = extension.packageJSON.version;
const previousVersion = context.globalState.get(GLOBAL_STATE_VERSION);

if (previousVersion !== currentVersion) {
updateExtension();
context.globalState.update(GLOBAL_STATE_VERSION, currentVersion);
}

let disposable = vscode.workspace.onDidChangeConfiguration((event) => {
if (event.affectsConfiguration(INCLUDE_CONFIG)) {
Expand Down

0 comments on commit 274100f

Please sign in to comment.