Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
The up to date decorator (👍) is now customizable from setting crates.…
Browse files Browse the repository at this point in the history
…upToDateDecorator #12
  • Loading branch information
serayuzgur committed Jul 4, 2018
1 parent 9225def commit 5f997ae
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ All notable changes to the "crates" extension will be documented in this file.
### 0.2.1
* Patreon link changed to a badge.
* Marketplace badges are linked to marketplace. [#13](https://github.com/serayuzgur/crates/issues/13).
* Package json improved.
* The up to date decorator (đź‘Ť) is now customizable from setting crates.upToDateDecorator [#12](https://github.com/serayuzgur/crates/issues/12).


### 0.2.0
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ Aims to be fast and simple.

## Extension Settings

No settings for now. It is so **simple** that you do not need any configuration.
It is so **simple** that you do not need any configuration, but if you insist...

`crates.upToDateDecorator :` The text to show when dependency is up to date. Default is đź‘Ť.

## Known Issues

Expand Down
26 changes: 24 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@
"name": "crates",
"displayName": "crates",
"description": "Aims to help rust developers to manage dependencies while using Cargo.toml. It is only helpful if you are using dependencies from crates.io.",
"version": "0.2.0",
"version": "0.2.1",
"publisher": "serayuzgur",
"author": {
"name": "serayuzgur",
"email": "[email protected]"
},
"license": "LICENSE",
"bugs": {
"url": "https://github.com/serayuzgur/crates/issues",
"email": "[email protected]"
},
"homepage": "https://github.com/serayuzgur/crates/blob/master/README.md",
"engines": {
"vscode": "^1.23.0"
},
Expand Down Expand Up @@ -37,7 +47,19 @@
"command": "crates.replaceVersion",
"title": "crates: Replace Version"
}
]
],
"configuration": {
"type": "object",
"title": "Crates configuration",
"properties": {
"crates.upToDateDecorator": {
"type": "string",
"scope": "resource",
"default": "đź‘Ť",
"description": "The text to show when dependency is up to date. "
}
}
}
},
"main": "./out/extension",
"scripts": {
Expand Down
24 changes: 21 additions & 3 deletions src/toml/decorations.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
/**
* Helps to manage decorations for the TOML files.
*/
import { DecorationOptions, Range, TextEditor, MarkdownString } from "vscode";
import {
workspace,
DecorationOptions,
Range,
TextEditor,
MarkdownString,
} from "vscode";
import { versions } from "../api";
import { statusBarItem } from "../ui/indicators";

Expand All @@ -17,6 +23,7 @@ function decoration(
crate: string,
version: string | any,
versions: string[],
upToDateDecorator: string,
) {
// Also handle json valued dependencies
const regex = new RegExp(`${crate}.*=.*`, "g");
Expand Down Expand Up @@ -67,7 +74,7 @@ function decoration(
hoverMessage,
renderOptions: {
after: {
contentText: hasLatest ? "đź‘Ť" : `Latest: ${versions[0]}`,
contentText: hasLatest ? upToDateDecorator : `Latest: ${versions[0]}`,
},
},
};
Expand All @@ -87,6 +94,11 @@ export function dependencies(
const options: DecorationOptions[] = [];
const responses = Object.keys(dependencies).map((key: string) => {
console.log("Fetching dependency: ", key);
const upToDateDecoratorConf = workspace
.getConfiguration("", editor.document.uri)
.get("crates.upToDateDecorator");

const upToDateDecorator = upToDateDecoratorConf ? upToDateDecoratorConf + "" : "";
return versions(key)
.then((json: any) => {
const versions = json.versions.reduce((result: any[], item: any) => {
Expand All @@ -95,7 +107,13 @@ export function dependencies(
}
return result;
}, []);
const decor = decoration(editor, key, dependencies[key], versions);
const decor = decoration(
editor,
key,
dependencies[key],
versions,
upToDateDecorator,
);
if (decor) {
options.push(decor);
}
Expand Down

0 comments on commit 5f997ae

Please sign in to comment.