Skip to content

Commit

Permalink
Merge pull request #670 from Hi-Windom/v0.32
Browse files Browse the repository at this point in the history
V0.32
  • Loading branch information
Soltus authored May 1, 2024
2 parents 2c12269 + a3a44e8 commit 27834b5
Show file tree
Hide file tree
Showing 68 changed files with 4,089 additions and 433 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ yarn.lock
/app/out
/app/dist-electron
**/node_modules
**.pyc
14 changes: 10 additions & 4 deletions .vscode/Sillot.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
{
"path": "../_vscode_plugin/Sillot", // 列出子文件夹,在父文件夹的 setting.json 添加隐藏(排除)
"name": "汐洛 VSC 插件🤍/_vscode_plugin/Sillot 🗂️"
"name": "汐洛 VSC 扩展🤍/_vscode_plugin/Sillot 🗂️"
},
{
"path": "../docs/starlight", // 列出子文件夹,在父文件夹的 setting.json 添加隐藏(排除)
Expand All @@ -32,15 +32,21 @@
"path": "../_sili", // 列出子文件夹,在父文件夹的 setting.json 添加隐藏(排除)
"name": "司丽🤍/_sili 🗂️"
},
{
"path": "../../Sillot-Be", // 列出子文件夹,在父文件夹的 setting.json 添加隐藏(排除)
"name": "汐洛 Chrome 扩展🤍../Sillot-Be 🗂️"
},
{
"path": "../_pkgs/siyuan", // 思源本源
"name": "思源🤍../siyuan 🗂️"
}
],
"settings": {
// "files.associations": {
// "*.sy": "json"
// },
"files.associations": {
// "*.sy": "json",
"*.tmTheme": "xml",
"*.tpl": "html"
},
"workbench.editor.wrapTabs": true,
"search.exclude": {
"**/.history": true
Expand Down
20 changes: 14 additions & 6 deletions _vscode_plugin/Sillot/grammars/sy.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,23 @@
]
},
"pair": {
"match": "\\s*\"(\\\\.|[^\"])*\"\\s*:\\s*\"(\\\\.|[^\"])*\"\\s*",
"captures": {
"1": {
"begin": "\"",
"end": "\"\\s*:\\s*\"",
"beginCaptures": {
"0": {
"name": "string.quoted.double.json"
},
"2": {
}
},
"endCaptures": {
"0": {
"name": "string.quoted.double.json"
}
}
},
"patterns": [
{
"include": "#value"
}
]
},
"array": {
"begin": "\\[",
Expand Down
67 changes: 66 additions & 1 deletion _vscode_plugin/Sillot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "sillot",
"displayName": "汐洛 Sillot",
"description": "汐洛(Sillot)孵化自思源笔记(siyuan-note),致力于服务智慧新彖乄。此插件为汐洛官方插件,提供多功能一体化集成。",
"version": "0.1.1610",
"version": "0.1.1700",
"preview": true,
"repository": "https://github.com/Hi-Windom/Sillot",
"publisher": "Hi-Windom",
Expand Down Expand Up @@ -42,10 +42,23 @@
"onLanguage:less",
"onLanguage:scss",
"onLanguage:python",
"onLanguage:xml",
"workspaceContains:**/.editorconfig"
],
"main": "./dist/extension.js",
"contributes": {
"themes": [
{
"label": "Sample Light",
"uiTheme": "vs",
"path": "./theme/Sample_Light.tmTheme"
},
{
"label": "Sample Dark",
"uiTheme": "vs-dark",
"path": "./theme/Sample_Dark.tmTheme"
}
],
"configuration": {
"type": "object",
"title": "汐洛插件配置",
Expand All @@ -70,6 +83,16 @@
}
},
"commands": [
{
"command": "extension.getGitHubUser",
"title": "Get GitHub User",
"category": "GitHub 认证 (共享)"
},
{
"command": "sillot.getGitHubUser",
"title": "Get GitHub User",
"category": "GitHub 认证 (独占)"
},
{
"command": "sillot.helloWorld",
"title": "Hello World",
Expand Down Expand Up @@ -181,6 +204,47 @@
"configuration": "./languages/_sy.language-configuration.json"
}
],
"codeActions": [
{
"languages": [
"sy"
],
"provider": "SyCodeActionProvider",
"providedCodeActionKinds": [
"quickfix",
"refactor",
"source",
"organizeImports"
],
"actions": {
"kind": "quickfix",
"title": "Fix sy error",
"description": "Fixes a JSON error in the current file"
}
}
],
"semanticTokenTypes": [
{
"id": "type",
"description": "Type names",
"defaultLegend": {
"tokenType": "type"
}
},
{
"id": "trailingComma",
"description": "Trailing commas in JSON",
"defaultLegend": {
"tokenType": "trailingComma"
}
}
],
"semanticTokenModifiers": [
{
"id": "error",
"description": "Indicates an error"
}
],
"grammars": [
{
"language": "sy",
Expand Down Expand Up @@ -239,6 +303,7 @@
"webpack-cli": "^5.1.4"
},
"dependencies": {
"@octokit/rest": "^20.1.0",
"fs-extra": "^11.2.0",
"json5": "^2.2.3"
}
Expand Down
63 changes: 63 additions & 0 deletions _vscode_plugin/Sillot/src/auth/github.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import * as vscode from 'vscode';
import * as Octokit from '@octokit/rest';

const GITHUB_AUTH_PROVIDER_ID = 'github';
// The GitHub Authentication Provider accepts the scopes described here:
// https://developer.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/
const SCOPES = ['user:email'];

export class Credentials {
private octokit: Octokit.Octokit | undefined;

async initialize(context: vscode.ExtensionContext): Promise<void> {
this.registerListeners(context);
await this.setOctokit();
}

private async setOctokit() {
/**
* By passing the `createIfNone` flag, a numbered badge will show up on the accounts activity bar icon.
* An entry for the sample extension will be added under the menu to sign in. This allows quietly
* prompting the user to sign in.
* */
const session = await vscode.authentication.getSession(GITHUB_AUTH_PROVIDER_ID, SCOPES, { createIfNone: false });

if (session) {
this.octokit = new Octokit.Octokit({
auth: session.accessToken
});

return;
}

this.octokit = undefined;
}

registerListeners(context: vscode.ExtensionContext): void {
/**
* Sessions are changed when a user logs in or logs out.
*/
context.subscriptions.push(vscode.authentication.onDidChangeSessions(async e => {
if (e.provider.id === GITHUB_AUTH_PROVIDER_ID) {
await this.setOctokit();
}
}));
}

async getOctokit(): Promise<Octokit.Octokit> {
if (this.octokit) {
return this.octokit;
}

/**
* When the `createIfNone` flag is passed, a modal dialog will be shown asking the user to sign in.
* Note that this can throw if the user clicks cancel.
*/
const session = await vscode.authentication.getSession(GITHUB_AUTH_PROVIDER_ID, SCOPES, { createIfNone: true });
this.octokit = new Octokit.Octokit({
auth: session.accessToken
});

return this.octokit;
}
}
37 changes: 35 additions & 2 deletions _vscode_plugin/Sillot/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as vscode from "vscode";
import fs from "fs-extra";
import json5 from "json5";
import { Log } from "./utils/log";
import { SyCompletionItemProvider, SyHoverProvider } from "./provider/sy";
import { SyCodeActionProvider, SyCompletionItemProvider, SyHoverProvider, SySemanticTokensProvider } from "./provider/sy";
import { IssueCompletionItems } from "./provider/db/Issue";
import { UserCompletionItems } from "./provider/db/User";
import { ClassCompletionItems } from "./provider/db/Class";
Expand Down Expand Up @@ -32,6 +32,9 @@ import { TestViewDragAndDrop } from "./testViewDragAndDrop";
import { JsonOutlineProvider } from "./jsonOutline";
import { subscribeToDocumentChanges, EMOJI_MENTION } from "./diagnostics";
import { CodelensProvider } from "./CodelensProvider";
import { GenericCompletionItemProvider } from "./provider/_Generic";
import { Credentials } from "./auth/github";
import { ColorPickerProvider } from "./provider/_ColorPicker";

let lastChangedDocument: vscode.TextDocument | null = null;
let myWebviewPanel: vscode.WebviewPanel | undefined;
Expand Down Expand Up @@ -73,7 +76,7 @@ async function loadCompletionItemsFromFile(filePath: string): Promise<Array<vsco
return items;
}

export function activate(context: vscode.ExtensionContext) {
export async function activate(context: vscode.ExtensionContext) {
const rootPath =
vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0
? vscode.workspace.workspaceFolders[0].uri.fsPath
Expand Down Expand Up @@ -278,8 +281,14 @@ export function activate(context: vscode.ExtensionContext) {
// context.subscriptions.push(disposable3);
context.subscriptions.push(测试序列化字典);
context.subscriptions.push(测试反序列化字典);
context.subscriptions.push(vscode.languages.registerCompletionItemProvider('*', new GenericCompletionItemProvider()));
context.subscriptions.push(vscode.languages.registerHoverProvider("sy", new SyHoverProvider()));
context.subscriptions.push(vscode.languages.registerCompletionItemProvider("sy", new SyCompletionItemProvider()));
context.subscriptions.push(vscode.languages.registerCodeActionsProvider({ language: 'sy' }, new SyCodeActionProvider()));
context.subscriptions.push(vscode.languages.registerDocumentSemanticTokensProvider({ language: 'sy' }, new SySemanticTokensProvider(), new vscode.SemanticTokensLegend([
'type',
'trailingComma', // 表示尾随逗号错误
])));
// context.subscriptions.push(vscode.languages.registerCompletionItemProvider("dosc", new SyCompletionItemProvider()));

const disposable5 = vscode.commands.registerCommand("sillot.pickEXE", () => {
Expand Down Expand Up @@ -344,6 +353,30 @@ export function activate(context: vscode.ExtensionContext) {
vscode.commands.registerCommand("codelens-sample.codelensAction", (args: any) => {
vscode.window.showInformationMessage(`CodeLens action clicked with args=${args}`);
});
const credentials = new Credentials();
await credentials.initialize(context);
const disposable99 = vscode.commands.registerCommand('extension.getGitHubUser', async () => {
/**
* Octokit (https://github.com/octokit/rest.js#readme) is a library for making REST API
* calls to GitHub. It provides convenient typings that can be helpful for using the API.
*
* Documentation on GitHub's REST API can be found here: https://docs.github.com/en/rest
*/
const octokit = await credentials.getOctokit();
const userInfo = await octokit.users.getAuthenticated();

vscode.window.showInformationMessage(`Logged into GitHub as ${userInfo.data.login}`);
});
const disposable88 = vscode.commands.registerCommand('sillot.getGitHubUser', async () => {
vscode.window.showInformationMessage("这个还没有实现嘞");
});
context.subscriptions.push(disposable88);
context.subscriptions.push(disposable99);

context.subscriptions.push(vscode.languages.registerColorProvider({ language: 'xml' }, new ColorPickerProvider())); // 记得在 .vscode 中把 .tmTheme 文件视为 xml
context.subscriptions.push(vscode.languages.registerColorProvider({ language: 'json' }, new ColorPickerProvider()));
context.subscriptions.push(vscode.languages.registerColorProvider({ language: 'typescript' }, new ColorPickerProvider()));
context.subscriptions.push(vscode.languages.registerColorProvider({ language: 'html' }, new ColorPickerProvider()));
}

// 当你的扩展被禁用时,这个方法将被调用
Expand Down
Loading

0 comments on commit 27834b5

Please sign in to comment.