Skip to content

Commit

Permalink
feat: hide classes that are only for typing from auto-completion (#1056)
Browse files Browse the repository at this point in the history
Closes #1026

### Summary of Changes

Classes that are only for typing (no constructor, no static members) do
not show up in auto-completion of references anymore. They also get
ranked down in the search of the documentation site.
  • Loading branch information
lars-reimann authored Apr 15, 2024
1 parent 604f382 commit 50851d7
Show file tree
Hide file tree
Showing 42 changed files with 234 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
search:
boost: 0.5
---

# `#!sds abstract class` InvertibleTableTransformer {#safeds.data.tabular.transformation.InvertibleTableTransformer data-toc-label='InvertibleTableTransformer'}

A `TableTransformer` that can also undo the learned transformation after it has been applied.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
search:
boost: 0.5
---

# `#!sds abstract class` TableTransformer {#safeds.data.tabular.transformation.TableTransformer data-toc-label='TableTransformer'}

Learn a transformation for a set of columns in a `Table` and transform another `Table` with the same columns.
Expand Down
5 changes: 5 additions & 0 deletions docs/api/safeds/data/tabular/typing/ColumnType.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
search:
boost: 0.5
---

# `#!sds abstract class` ColumnType {#safeds.data.tabular.typing.ColumnType data-toc-label='ColumnType'}

Abstract base class for column types.
Expand Down
5 changes: 5 additions & 0 deletions docs/api/safeds/data/tabular/typing/Schema.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
search:
boost: 0.5
---

# `#!sds abstract class` Schema {#safeds.data.tabular.typing.Schema data-toc-label='Schema'}

Store column names and corresponding data types for a `Table` or `Row`.
Expand Down
5 changes: 5 additions & 0 deletions docs/api/safeds/lang/Any.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
search:
boost: 0.5
---

# `#!sds abstract class` Any {#safeds.lang.Any data-toc-label='Any'}

The common superclass of all classes.
Expand Down
5 changes: 5 additions & 0 deletions docs/api/safeds/lang/Boolean.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
search:
boost: 0.5
---

# `#!sds abstract class` Boolean {#safeds.lang.Boolean data-toc-label='Boolean'}

A truth value.
Expand Down
5 changes: 5 additions & 0 deletions docs/api/safeds/lang/Float.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
search:
boost: 0.5
---

# `#!sds abstract class` Float {#safeds.lang.Float data-toc-label='Float'}

A floating-point number.
Expand Down
5 changes: 5 additions & 0 deletions docs/api/safeds/lang/Int.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
search:
boost: 0.5
---

# `#!sds abstract class` Int {#safeds.lang.Int data-toc-label='Int'}

An integer.
Expand Down
5 changes: 5 additions & 0 deletions docs/api/safeds/lang/List.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
search:
boost: 0.5
---

# `#!sds abstract class` List {#safeds.lang.List data-toc-label='List'}

A list of elements.
Expand Down
5 changes: 5 additions & 0 deletions docs/api/safeds/lang/Map.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
search:
boost: 0.5
---

# `#!sds abstract class` Map {#safeds.lang.Map data-toc-label='Map'}

A map of keys to values.
Expand Down
5 changes: 5 additions & 0 deletions docs/api/safeds/lang/Nothing.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
search:
boost: 0.5
---

# `#!sds abstract class` Nothing {#safeds.lang.Nothing data-toc-label='Nothing'}

The common subclass of all classes.
Expand Down
5 changes: 5 additions & 0 deletions docs/api/safeds/lang/Number.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
search:
boost: 0.5
---

# `#!sds abstract class` Number {#safeds.lang.Number data-toc-label='Number'}

A number.
Expand Down
5 changes: 5 additions & 0 deletions docs/api/safeds/lang/String.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
search:
boost: 0.5
---

# `#!sds abstract class` String {#safeds.lang.String data-toc-label='String'}

Some text.
Expand Down
5 changes: 5 additions & 0 deletions docs/api/safeds/ml/classical/classification/Classifier.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
search:
boost: 0.5
---

# `#!sds abstract class` Classifier {#safeds.ml.classical.classification.Classifier data-toc-label='Classifier'}

Abstract base class for all classifiers.
Expand Down
5 changes: 5 additions & 0 deletions docs/api/safeds/ml/classical/regression/Regressor.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
search:
boost: 0.5
---

# `#!sds abstract class` Regressor {#safeds.ml.classical.regression.Regressor data-toc-label='Regressor'}

Abstract base class for all regressors.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
SdsTypeParameter,
} from '../generated/ast.js';
import {
Class,
getClassMembers,
getColumns,
getEnumVariants,
Expand Down Expand Up @@ -441,7 +442,9 @@ export class SafeDsMarkdownGenerator {
}

private renderPreamble(node: SdsDeclaration, state: DetailsState, kind: string, keyword: string = kind): string {
let result = this.renderHeading(node, state, keyword) + '\n';
let result = this.renderFrontMatter(node);

result += this.renderHeading(node, state, keyword) + '\n';

const deprecationWarning = this.renderDeprecationWarning(node, kind);
if (deprecationWarning) {
Expand All @@ -455,6 +458,14 @@ export class SafeDsMarkdownGenerator {
return result;
}

private renderFrontMatter(node: SdsDeclaration): string {
if (isSdsClass(node) && Class.isOnlyForTyping(node)) {
return `---\nsearch:\n boost: 0.5\n---\n\n`;
}

return '';
}

private renderHeading(node: SdsDeclaration, state: DetailsState, keyword: string): string {
let result = '#'.repeat(Math.min(state.level, 6));
result += this.renderMaturity(node);
Expand Down
9 changes: 9 additions & 0 deletions packages/safe-ds-lang/src/language/helpers/nodeProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ export namespace Argument {
};
}

export namespace Class {
/**
* Checks whether the class is only for typing, i.e. whether it has no constructor and no static members.
*/
export const isOnlyForTyping = (node: SdsClass | undefined): boolean => {
return isSdsClass(node) && !node.parameterList && !getClassMembers(node).some((it) => isStatic(it));
};
}

export namespace Enum {
export const isConstant = (node: SdsEnum | undefined): boolean => {
return Boolean(node) && getEnumVariants(node).every((it) => EnumVariant.isConstant(it));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
SdsPipeline,
SdsSchema,
} from '../generated/ast.js';
import { getPackageName } from '../helpers/nodeProperties.js';
import { Class, getPackageName } from '../helpers/nodeProperties.js';
import { isInPipelineFile, isInStubFile } from '../helpers/fileExtensions.js';
import { classTypeParameterIsUsedInCorrectPosition } from '../validation/other/declarations/typeParameters.js';

Expand Down Expand Up @@ -63,7 +63,11 @@ export class SafeDsCompletionProvider extends DefaultCompletionProvider {
);
}
} else if (isSdsReference(refInfo.container)) {
return !this.illegalNodeTypesForReferences.has(description.type);
if (this.illegalNodeTypesForReferences.has(description.type)) {
return false;
} else if (isSdsClass(description.node) && Class.isOnlyForTyping(description.node)) {
return false;
}
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,23 @@ describe('SafeDsCompletionProvider', async () => {
shouldNotContain: ['g2'],
},
},
{
testName: 'reference (class only for typing)',
code: `
class MyClass1
class MyClass2()
class MyClass3 {
static attr myAttribute: Int
}
pipeline myPipeline {
<|>
`,
expectedLabels: {
shouldContain: ['MyClass2', 'MyClass3'],
shouldNotContain: ['MyClass1'],
},
},
{
testName: 'type arguments (no prefix)',
code: `
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
search:
boost: 0.5
---

# :warning:{ title="Deprecated" } `#!sds abstract class` MyClass1 {#tests.generation.markdown.classes.deprecated.MyClass1 data-toc-label='MyClass1'}

!!! warning "Deprecated"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
search:
boost: 0.5
---

# `#!sds abstract class` MyClass1 {#tests.generation.markdown.classes.documented.MyClass1 data-toc-label='MyClass1'}

Description of MyClass1.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
search:
boost: 0.5
---

# `#!sds abstract class` MyClass3 {#tests.generation.markdown.classes.documented.MyClass3 data-toc-label='MyClass3'}

Description of MyClass3.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
search:
boost: 0.5
---

# `#!sds abstract class` MyClass5 {#tests.generation.markdown.classes.documented.MyClass5 data-toc-label='MyClass5'}

Description of MyClass5.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ Description of myFunction2.
@Pure static fun myFunction2()
```

---
search:
boost: 0.5
---

## `#!sds abstract class` MyClass7 {#tests.generation.markdown.classes.documented.MyClass6.MyClass7 data-toc-label='MyClass7'}

Description of MyClass7.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
search:
boost: 0.5
---

# `#!sds abstract class` MyClass7 {#tests.generation.markdown.classes.documented.MyClass7 data-toc-label='MyClass7'}

Description of MyClass7.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
search:
boost: 0.5
---

# `#!sds abstract class` MyClass8 {#tests.generation.markdown.classes.documented.MyClass8 data-toc-label='MyClass8'}

Description of MyClass8.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
search:
boost: 0.5
---

# :test_tube:{ title="Experimental" } `#!sds abstract class` MyClass1 {#tests.generation.markdown.classes.experimental.MyClass1 data-toc-label='MyClass1'}

??? quote "Stub code in `main.sdsstub`"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
search:
boost: 0.5
---

# `#!sds abstract class` MyClass1 {#tests.generation.markdown.classes.undocumented.MyClass1 data-toc-label='MyClass1'}

??? quote "Stub code in `main.sdsstub`"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
search:
boost: 0.5
---

# `#!sds abstract class` MyClass3 {#tests.generation.markdown.classes.undocumented.MyClass3 data-toc-label='MyClass3'}

**Type parameters:**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
search:
boost: 0.5
---

# `#!sds abstract class` MyClass5 {#tests.generation.markdown.classes.undocumented.MyClass5 data-toc-label='MyClass5'}

**Parent type:** [`MyClass1`][tests.generation.markdown.classes.undocumented.MyClass1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
@Pure static fun myFunction2()
```

---
search:
boost: 0.5
---

## `#!sds abstract class` MyClass7 {#tests.generation.markdown.classes.undocumented.MyClass6.MyClass7 data-toc-label='MyClass7'}

??? quote "Stub code in `main.sdsstub`"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
search:
boost: 0.5
---

# `#!sds abstract class` MyClass7 {#tests.generation.markdown.classes.undocumented.MyClass7 data-toc-label='MyClass7'}

Description of MyClass7.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
search:
boost: 0.5
---

# `#!sds abstract class` MyClass1 {#tests.generation.markdown.enums.documented.MyClass1 data-toc-label='MyClass1'}

??? quote "Stub code in `main.sdsstub`"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
search:
boost: 0.5
---

# `#!sds abstract class` MyClass1 {#tests.generation.markdown.functions.documented.MyClass1 data-toc-label='MyClass1'}

??? quote "Stub code in `main.sdsstub`"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
search:
boost: 0.5
---

# `#!sds abstract class` MyClass2 {#tests.generation.markdown.linkTag.MyClass2 data-toc-label='MyClass2'}

??? quote "Stub code in `main.sdsstub`"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
search:
boost: 0.5
---

# `#!sds abstract class` MyClass1 {#tests.generation.markdown.multiline.MyClass1 data-toc-label='MyClass1'}

Description of MyClass1.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
search:
boost: 0.5
---

# `#!sds abstract class` MyClass {#tests.generation.markdown.schemas.documented.MyClass data-toc-label='MyClass'}

??? quote "Stub code in `main.sdsstub`"
Expand Down
Loading

0 comments on commit 50851d7

Please sign in to comment.