Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(commands): add "ansible.server.showMetaData" command #24

Merged
merged 1 commit into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ You can also run the installation command manually.
- `~/AppData/Local/coc/extensions/@yaegassy/coc-ansible-data/ansible/venv/Scripts/yamllint.exe`
- **[Note]** `ansible` is a very large tool and will take some time to install
- `ansible.server.restart`: Restart ansible language server
- `ansible.server.showMetaData`: Show ansible-metadata for ansible language server
- `ansible.ansbileDoc.showInfo`: Run the `ansible-doc` command in a terminal window with various options to display information about the plugins | [DEMO](https://github.com/yaegassy/coc-ansible/pull/22#issuecomment-1178586815)
- `ansible.ansbileDoc.showSnippets`: Run the `ansible-doc` command in a terminal window with various options to display a snippets of the plugins | [DEMO](https://github.com/yaegassy/coc-ansible/pull/22#issuecomment-1178587359)

Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,10 @@
"command": "ansible.server.restart",
"title": "Restart ansible language server"
},
{
"command": "ansible.server.showMetaData",
"title": "Show ansible-metadata for ansible language server"
},
{
"command": "ansible.ansbileDoc.showInfo",
"title": "Run the `ansible-doc` command in a terminal window with various options to display information about the plugins"
Expand Down
27 changes: 27 additions & 0 deletions src/commands/serverShowMetaData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { commands, ExtensionContext, LanguageClient, NotificationType, workspace } from 'coc.nvim';

export async function activate(context: ExtensionContext, client: LanguageClient) {
await client.onReady();

client.onNotification(new NotificationType(`update/ansible-metadata`), async (ansibleMetaDataList: any) => {
const outputText = JSON.stringify(ansibleMetaDataList, null, 2);

await workspace.nvim
.command(
'belowright vnew ansible-server-metadata | setlocal buftype=nofile bufhidden=hide noswapfile filetype=json'
)
.then(async () => {
const buf = await workspace.nvim.buffer;
buf.setLines(outputText.split('\n'), { start: 0, end: -1 });
});
});

context.subscriptions.push(
commands.registerCommand('ansible.server.showMetaData', async () => {
const { document } = await workspace.getCurrentState();
if (document.languageId !== 'ansible') return;

client.sendNotification(new NotificationType(`update/ansible-metadata`), [document.uri.toString()]);
})
);
}
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import * as ansibleDocShowInfoCommandFeature from './commands/ansibleDocShowInfo
import * as ansibleDocShowSnippetsCommandFeature from './commands/ansibleDocShowSnippets';
import * as builtinInstallRequirementsToolsCommandFeature from './commands/builtinInstallRequirementsTools';
import * as serverRestartCommandFeature from './commands/serverRestart';
import * as serverShowMetaDataCommandFeature from './commands/serverShowMetaData';

let client: LanguageClient;
let extensionStoragePath: string;
Expand Down Expand Up @@ -180,6 +181,7 @@ export async function activate(context: ExtensionContext): Promise<void> {

// commands
serverRestartCommandFeature.activate(context, client);
serverShowMetaDataCommandFeature.activate(context, client);
if (pythonCommandPaths) {
builtinInstallRequirementsToolsCommandFeature.activate(context, pythonCommandPaths, client);
}
Expand Down