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

Quick fix for namespace not opened. #1335

Open
DmitryVasilevsky opened this issue Mar 28, 2024 · 2 comments
Open

Quick fix for namespace not opened. #1335

DmitryVasilevsky opened this issue Mar 28, 2024 · 2 comments
Labels
enhancement New feature or request hack-candidates collecting candidate issues

Comments

@DmitryVasilevsky
Copy link
Contributor

If I type a function from a namespace that's not opened, the editor will auto-insert "open" statement for me. However, if I copy/paste the same function, it won't auto-insert that open statement, which is OK. However, there's no Quick Fix for this, which is annoying.

@DmitryVasilevsky DmitryVasilevsky added enhancement New feature or request needs triage labels Mar 28, 2024
@saram-aman
Copy link

@DmitryVasilevsky please assign the task to me.

@minestarks minestarks added hack-candidates collecting candidate issues and removed needs triage labels May 22, 2024
@minestarks
Copy link
Member

For reference, code example:

Q# Playground link

namespace Test {
    @EntryPoint()
    operation Main() : Unit {
        // name error: `DumpMachine` not found.
        // A quick fix should be offered here, which would add an
        // open statement at the top of the namespace.
        DumpMachine(); 
    }
}


namespace Test2 {
    // This shows what a proper open statement would look like.
    open Microsoft.Quantum.Diagnostics;

    @EntryPoint()
    operation Main() : Unit {
        DumpMachine();
    }
}

CONTRIBUTORS PLEASE READ

Getting started

Welcome! Please take a look through our README to orient yourself in the repo and find instructions on how to build.

For this issue, you'll want to have a working knowledge of Rust and VS Code features. Knowing TypeScript or JavaScript might be useful, but it's not necessary, since the fix will likely be entirely in the Rust part of the codebase.

Background: Quick fixes

For this issue, you'll want to be familiar with the Quick Fix feature in VS Code.

Some VS Code resources:

Code Actions = Quick Fixes and refactorings (VS Code user documentation))

Possible Actions on Errors or Warnings (VS Code extension documentation)

#1495 adds support for Code Actions in the Q# extension. Try out our existing quick fixes to get a feel for how they work in the editor.

Auto-opening namespaces

You'll probably want to share some of the code from the Completions feature. The auto-open feature already implements a lot of the "brains" necessary to get this quick fix to work.

To get a feel for how auto-opening namespaces are implemented today, start typing DumpMachine in the editor, then select the auto-completed item from the completions list. Notice how an open statement is added at the top.

auto-open-namespace

We want the new quick fix to perform this same action.

Completions are implemented at:
qsharp/language_service/src/completion.rs at main · microsoft/qsharp (github.com)

Testing

You can demonstrate that the quick fix works by running the playground locally (see the code example at the top of this comment).

Please add unit tests verifying the functionality you implemented.

Before you submit a pull request please run python ./build.py to ensure the project builds cleanly. See README for details.

Reviews

Please ensure your code is tested, clean and well refactored before opening a pull request. If you're not sure, feel free to open a draft PR for preliminary feedback.

Once you have published your PR, the codeowners will automatically get tagged and we'll review shortly.

If you need clarification on an issue please tag @minestarks with your questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hack-candidates collecting candidate issues
Projects
None yet
Development

No branches or pull requests

3 participants