Skip to content

Commit

Permalink
fix: proper semantic highlighting and formatting for type declarations (
Browse files Browse the repository at this point in the history
  • Loading branch information
ymc9 authored Nov 23, 2024
1 parent 83936da commit b7c6c87
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
6 changes: 6 additions & 0 deletions packages/ide/jetbrains/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## [Unreleased]

### Fixed

- Proper semantic highlighting and formatting for type declarations.

## 2.9.0

### Added

- Support for using `@@validate` attribute inside type declarations.
Expand Down
8 changes: 4 additions & 4 deletions packages/schema/src/language-server/zmodel-formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export class ZModelFormatter extends AbstractFormatter {
protected format(node: AstNode): void {
const formatter = this.getNodeFormatter(node);

if (ast.isDataModelField(node)) {
if (this.isPrismaStyle && ast.isDataModel(node.$container)) {
if (ast.isDataModelField(node) || ast.isTypeDefField(node)) {
if (this.isPrismaStyle && (ast.isDataModel(node.$container) || ast.isTypeDef(node.$container))) {
const dataModel = node.$container;

const compareFn = (a: number, b: number) => b - a;
Expand Down Expand Up @@ -104,14 +104,14 @@ export class ZModelFormatter extends AbstractFormatter {
this.isPrismaStyle = isPrismaStyle;
}

private getFieldTypeLength(field: ast.DataModelField) {
private getFieldTypeLength(field: ast.DataModelField | ast.TypeDefField) {
let length: number;

if (field.type.type) {
length = field.type.type.length;
} else if (field.type.reference) {
length = field.type.reference.$refText.length;
} else if (field.type.unsupported) {
} else if (ast.isDataModelField(field) && field.type.unsupported) {
const name = `Unsupported("${field.type.unsupported.value.value}")`;
length = name.length;
} else {
Expand Down
5 changes: 4 additions & 1 deletion packages/schema/src/language-server/zmodel-semantic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
isPlugin,
isPluginField,
isReferenceExpr,
isTypeDef,
isTypeDefField,
} from '@zenstackhq/language/ast';
import { AbstractSemanticTokenProvider, AstNode, SemanticTokenAcceptor } from 'langium';
import { SemanticTokenTypes } from 'vscode-languageserver';
Expand All @@ -36,14 +38,15 @@ export class ZModelSemanticTokenProvider extends AbstractSemanticTokenProvider {
property: 'superTypes',
type: SemanticTokenTypes.type,
});
} else if (isDataSource(node) || isGeneratorDecl(node) || isPlugin(node) || isEnum(node)) {
} else if (isDataSource(node) || isGeneratorDecl(node) || isPlugin(node) || isEnum(node) || isTypeDef(node)) {
acceptor({
node,
property: 'name',
type: SemanticTokenTypes.type,
});
} else if (
isDataModelField(node) ||
isTypeDefField(node) ||
isConfigField(node) ||
isAttributeArg(node) ||
isPluginField(node) ||
Expand Down

0 comments on commit b7c6c87

Please sign in to comment.