From 1d758e7fff945fda1d13c9a89c4536c7c0339661 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Sun, 31 Dec 2023 12:36:51 +0100 Subject: [PATCH] Version 0.2.1 --- CHANGELOG.md | 19 +++++++-- Cargo.lock | 2 +- Cargo.toml | 2 +- editors/vscode/package-lock.json | 4 +- editors/vscode/package.json | 6 ++- editors/vscode/src/auth/github.ts | 61 ++++++++++++++++------------- editors/vscode/src/commands/auth.ts | 6 +++ src/lang/toml/array.rs | 14 +++---- src/lang/toml/table.rs | 13 +++--- 9 files changed, 73 insertions(+), 54 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99e725f..019826d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## `0.2.1` - December 31st, 2023 + +### Added + +- Added a VSCode extension command to manually set a GitHub Personal Access Token. + If you are using a private Wally registry and the index repository is not public, you will need to set this for the extension to work. + +### Fixed + +- Fixed crash when encountering empty TOML sections + ## `0.2.0` - October 30th, 2023 ### Added @@ -19,14 +30,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- Fixed invalid diagnostics for wally dev dependencies +- Fixed invalid diagnostics for Wally dev dependencies ## `0.1.0` - September 26th, 2023 ### Added -- Added diagnostics for unsupported operating system and/or architecture (aftman) -- Added diagnostics for invalid dependency realms (wally) +- Added diagnostics for unsupported operating system and/or architecture (Aftman) +- Added diagnostics for invalid dependency realms (Wally) ### Changed @@ -54,7 +65,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- Fixed crash for wally manifests with empty dependency sections: +- Fixed crash for Wally manifests with empty dependency sections: ```toml # No longer crashes diff --git a/Cargo.lock b/Cargo.lock index c8a17bf..894fc11 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1914,7 +1914,7 @@ dependencies = [ [[package]] name = "tooling-language-server" -version = "0.2.0" +version = "0.2.1" dependencies = [ "anyhow", "async-channel", diff --git a/Cargo.toml b/Cargo.toml index 6970d00..0a33389 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tooling-language-server" -version = "0.2.0" +version = "0.2.1" edition = "2021" description = "A language server for tooling" keywords = ["lsp", "language-server", "tower"] diff --git a/editors/vscode/package-lock.json b/editors/vscode/package-lock.json index 9d29b8d..f27db28 100644 --- a/editors/vscode/package-lock.json +++ b/editors/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "tooling-language-server", - "version": "0.2.0", + "version": "0.2.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "tooling-language-server", - "version": "0.2.0", + "version": "0.2.1", "license": "MPL-2.0", "dependencies": { "axios": "^1.5.0", diff --git a/editors/vscode/package.json b/editors/vscode/package.json index cd48997..cb3bd12 100644 --- a/editors/vscode/package.json +++ b/editors/vscode/package.json @@ -2,7 +2,7 @@ "name": "tooling-language-server", "displayName": "Tooling Language Server", "description": "A language server for tooling", - "version": "0.2.0", + "version": "0.2.1", "license": "MPL-2.0", "publisher": "filiptibell", "author": { @@ -38,6 +38,10 @@ } ], "commands": [ + { + "command": "tooling-language-server.promptAuthForGitHub", + "title": "Tooling Language Server - Add GitHub Personal Access Token" + }, { "command": "tooling-language-server.resetAuthForGitHub", "title": "Tooling Language Server - Reset GitHub Personal Access Token" diff --git a/editors/vscode/src/auth/github.ts b/editors/vscode/src/auth/github.ts index c9e99cf..406ca5d 100644 --- a/editors/vscode/src/auth/github.ts +++ b/editors/vscode/src/auth/github.ts @@ -34,38 +34,43 @@ const validate = async (token: string): Promise => { Any token returned from this function is guaranteed to currently be valid. */ -export const prompt = async (): Promise => { +export const prompt = async ( + skipNotification?: true +): Promise => { const context = getExtensionContext(); - const result = await vscode.window.showInformationMessage( - "The GitHub API rate limit has been reached." + - "\nSome functionality will be disabled until authenticated.", - "Set Personal Access Token" - ); - - if (result === "Set Personal Access Token") { - let prompt = "Enter a token"; - while (true) { - const token = await vscode.window.showInputBox({ - prompt, - title: "GitHub Personal Access Token", - password: true, - ignoreFocusOut: true, - }); - if (token !== undefined) { - if (token !== "" && (await validate(token))) { - await context.globalState.update( - GITHUB_AUTH_TOKEN_STORAGE_KEY, - token - ); - return token; - } else { - prompt = "Token is not valid. Enter a new token"; - continue; - } + if (skipNotification !== true) { + const result = await vscode.window.showInformationMessage( + "The GitHub API rate limit has been reached." + + "\nSome functionality will be disabled until authenticated.", + "Set Personal Access Token" + ); + if (result !== "Set Personal Access Token") { + return null; + } + } + + let prompt = "Enter a token"; + while (true) { + const token = await vscode.window.showInputBox({ + prompt, + title: "GitHub Personal Access Token", + password: true, + ignoreFocusOut: true, + }); + if (token !== undefined) { + if (token !== "" && (await validate(token))) { + await context.globalState.update( + GITHUB_AUTH_TOKEN_STORAGE_KEY, + token + ); + return token; } else { - break; + prompt = "Token is not valid. Enter a new token"; + continue; } + } else { + break; } } diff --git a/editors/vscode/src/commands/auth.ts b/editors/vscode/src/commands/auth.ts index 1aeb6d9..ed9e49a 100644 --- a/editors/vscode/src/commands/auth.ts +++ b/editors/vscode/src/commands/auth.ts @@ -2,11 +2,17 @@ import * as client from "../client"; import auth from "../auth"; +export const promptAuthForGitHub = async (args: {}) => { + await auth.github.prompt(true); + await client.restartServer(); +}; + export const resetAuthForGitHub = async (args: {}) => { await auth.github.reset(); await client.restartServer(); }; export default { + promptAuthForGitHub, resetAuthForGitHub, }; diff --git a/src/lang/toml/array.rs b/src/lang/toml/array.rs index c600a21..04e3160 100644 --- a/src/lang/toml/array.rs +++ b/src/lang/toml/array.rs @@ -14,19 +14,15 @@ impl TomlArray { match node.as_array() { None => None, Some(array) => { - let mut range_first = None; - let mut range_last = None; + // NOTE: Node is guaranteed to have at least one text range + let mut text_range = node.text_ranges().next().unwrap(); for range in node.text_ranges() { - if range_first.is_none() { - range_first = Some(range) - } else { - range_last = Some(range) - } + text_range = text_range.cover(range); } let span = Range { - start: u32::from(range_first.unwrap().start()) as usize, - end: u32::from(range_last.unwrap().end()) as usize, + start: u32::from(text_range.start()) as usize, + end: u32::from(text_range.end()) as usize, }; let source = source.as_ref(); diff --git a/src/lang/toml/table.rs b/src/lang/toml/table.rs index 9d72e48..1c0ed1c 100644 --- a/src/lang/toml/table.rs +++ b/src/lang/toml/table.rs @@ -14,18 +14,15 @@ impl TomlTable { match node.as_table() { None => None, Some(table) => { - let mut range_first = None; - let mut range_last = None; + // NOTE: Node is guaranteed to have at least one text range + let mut text_range = node.text_ranges().next().unwrap(); for range in node.text_ranges() { - if range_first.is_none() { - range_first = Some(range) - } - range_last = Some(range) + text_range = text_range.cover(range); } let span = Range { - start: u32::from(range_first?.start()) as usize, - end: u32::from(range_last?.end()) as usize, + start: u32::from(text_range.start()) as usize, + end: u32::from(text_range.end()) as usize, }; let source = source.as_ref();