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

Update test callable discovery to work within the language service #2095

Open
wants to merge 60 commits into
base: main
Choose a base branch
from

Conversation

sezna
Copy link
Contributor

@sezna sezna commented Jan 7, 2025

This PR rewrites #2059 to trigger test discovery from within the language server, as opposed to externally in an entirely separate context. Please read the description in that PR for more detail.

It also adds tests for LS state in both the Rust-based LS tests and the JS-based basics.js npm API tests.

@sezna sezna marked this pull request as ready for review January 7, 2025 20:37
@sezna sezna changed the base branch from alex/testHarness to main January 7, 2025 23:41
Copy link
Member

@minestarks minestarks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not done looking at all the files, posting all my comments for today.

Comment on lines +32 to +35
let location = Location {
source: source.name.clone(),
range: Range::from_span(Encoding::Utf8, &source.contents, &(span - source.offset)),
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JavaScript is utf-16 😭 and that's why we can't make assumptions in the native crates about encoding (utf-8 for Rust/Python, utf-16 for JavaScript). This function should take position_encoding as a parameter.

But also... This is just dead code now. Do we still want to expose ICompiler.getTestCallables()? I think we should just remove it since it's not used in the new approach.

serializable_type! {
TestDescriptor,
{
#[serde(rename = "callableName")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The serializable_type! macro puts #[serde(rename_all = "camelCase")] over the struct definition so the properties should automatically be camel cased, so you don't need this attribute. Hopefully.

}

#[wasm_bindgen]
pub fn get_test_callables(config: ProgramConfig) -> Result<Vec<ITestDescriptor>, String> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dead code?


#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(typescript_type = "(callables: [string, ILocation][]) => void")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the ITestCallable type you already defined in the other wasm file, instead of the [string, ILocation] tuple. Tuples are clunky in TS.

@@ -26,8 +26,7 @@ import {
} from "../workers/common.js";
type QscWasm = typeof import("../../lib/web/qsc_wasm.js");

// Only one event type for now
export type LanguageServiceEvent = {
export type LanguageServiceDiagnosticEvent = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow I had totally forgotten that diagnostics were Events at this layer. I'm so happy/relieved to rediscover this. Since we're not plumbing callback arguments through seven layers of JavaScript, it's not going to be a QCOM breaking change :)

@@ -274,6 +285,18 @@ export class QSharpLanguageService implements ILanguageService {
log.error("Error in onDiagnostics", e);
}
}

async onTestCallables(callables: [string, ILocation][]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in the WASM layer, I think this type can be ITestCallables instead of a tuple, the reasoning being that objects are just easier to use/read in JavaScript

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the changes in this file are dead code now.

let test_callables_callback = move |update: TestCallables| {
let callables = update
.callables
.iter()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can .into_iter() this and avoid cloning the contents.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants