Skip to content

Commit

Permalink
fix: signature help for optional parameters (#793)
Browse files Browse the repository at this point in the history
Closes #791

### Summary of Changes

Optional parameters in the signature help now get highlighted properly.
  • Loading branch information
lars-reimann committed Nov 22, 2023
1 parent 5536a4a commit fd88ce8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type {
} from 'vscode-languageserver';
import { createMarkupContent } from '../documentation/safe-ds-comment-provider.js';
import { isSdsAbstractCall, SdsCallable, SdsParameter } from '../generated/ast.js';
import { getParameters } from '../helpers/nodeProperties.js';
import { getParameters, Parameter } from '../helpers/nodeProperties.js';
import { type SafeDsNodeMapper } from '../helpers/safe-ds-node-mapper.js';
import type { SafeDsServices } from '../safe-ds-module.js';
import { type SafeDsTypeComputer } from '../typing/safe-ds-type-computer.js';
Expand Down Expand Up @@ -108,8 +108,9 @@ export class SafeDsSignatureHelpProvider implements SignatureHelpProvider {
};

private getParameterLabel = (parameter: SdsParameter) => {
const optionality = Parameter.isOptional(parameter) ? '?' : '';
const type = this.typeComputer.computeType(parameter);
return `${parameter.name}: ${type}`;
return `${parameter.name}${optionality}: ${type}`;
};

/* c8 ignore start */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,28 @@ describe('SafeDsSignatureHelpProvider', async () => {
},
],
},
// https://github.com/Safe-DS/DSL/issues/791
{
testName: 'optional parameter',
code: `
fun f(p: Int = 0)
pipeline myPipeline {
f(»«);
}
`,
expectedSignature: [
{
label: 'f(p?: Int) -> ()',
documentation: undefined,
parameters: [
{
label: 'p?: Int',
},
],
},
],
},
])('should assign the correct signature ($testName)', async ({ code, expectedSignature }) => {
const actualSignatureHelp = await getActualSignatureHelp(code);
expect(actualSignatureHelp?.signatures).toStrictEqual(expectedSignature);
Expand Down

0 comments on commit fd88ce8

Please sign in to comment.