Skip to content

Commit

Permalink
refreshLinks command
Browse files Browse the repository at this point in the history
  • Loading branch information
hahnbeelee committed Jul 13, 2022
1 parent 735eda6 commit 39121b1
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3185,6 +3185,10 @@
"command": "mintlify.refresh-links",
"title": "Refresh links"
},
{
"command": "mintlify.refreshLinks",
"title": "Refresh Mintlify links"
},
{
"command": "mintlify.prefill-doc",
"title": "Prefill document"
Expand Down
1 change: 1 addition & 0 deletions vscode/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export * from './commands/externalDiff';
export * from './commands/gitCommands';
export * from './commands/inviteToLiveShare';
export * from './commands/logging';
export * from './commands/mintlify/refreshLinks';
export * from './commands/openAssociatedPullRequestOnRemote';
export * from './commands/openBranchesOnRemote';
export * from './commands/openBranchOnRemote';
Expand Down
29 changes: 29 additions & 0 deletions vscode/src/commands/mintlify/refreshLinks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import axios from 'axios';
import { TextEditor } from 'vscode';
import { Commands, ContextKeys } from '../../constants';
import type { Container } from '../../container';
import { setContext } from '../../context';
import { API_ENDPOINT } from '../../mintlify-functionality/utils/api';
import { getRepoInfo } from '../../mintlify-functionality/utils/git';
import { command } from '../../system/command';
import { ActiveEditorCommand } from '../base';

@command()
export class RefreshLinks extends ActiveEditorCommand {
constructor(private readonly container: Container) {
super(Commands.RefreshLinks);
}

async execute(editor: TextEditor) {
const fileFsPath: string = editor.document.uri.fsPath;
const { gitOrg, repo } = await getRepoInfo(fileFsPath);
try {
const codesResponse = await axios.get(`${API_ENDPOINT}/links`, {
params: { ...this.container.storage.getAuthParams(), repo: repo, gitOrg: gitOrg },
});
await setContext(ContextKeys.Links, codesResponse.data.codes);
} catch (err) {
// TODO - proper error handling
}
}
}
3 changes: 3 additions & 0 deletions vscode/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ export const enum Commands {
Deprecated_OpenInRemote = 'gitlens.openInRemote',
Deprecated_OpenRepoInRemote = 'gitlens.openRepoInRemote',
Deprecated_ShowFileHistoryInView = 'gitlens.showFileHistoryInView',

// mintlify
RefreshLinks = 'mintlify.refreshLinks',
}

export const enum ContextKeys {
Expand Down
1 change: 1 addition & 0 deletions vscode/src/mintlify-functionality/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export const prefillDocCommand = (viewProvider: ViewProvider) => {
});
};

// TODO - update this to correspond with git line changes
export const highlightConnectionCommand = () => {
return vscode.commands.registerCommand('mintlify.highlight-connection', async (code: CodeReturned) => {
if (code.line != null && code.endLine != null) {
Expand Down

0 comments on commit 39121b1

Please sign in to comment.