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

feat!: implement language service #152

Merged
merged 8 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@
"editor.wordWrapColumn": 100,
"editor.rulers": [100]
},
"todo-tree.highlights.enabled": false
"todo-tree.highlights.enabled": false,
"jestrunner.jestCommand": "clear; node --no-warnings --experimental-vm-modules ./node_modules/jest/bin/jest.js",
"jestrunner.changeDirectoryToWorkspaceRoot": false
}
2 changes: 1 addition & 1 deletion conver.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@knuckles/config": "minor",
"@knuckles/eslint": "minor",
"@knuckles/fabricator": "minor",
"@knuckles/language-server": "minor",
"@knuckles/language-service": "minor",
"@knuckles/location": "minor",
"@knuckles/parser": "minor",
"@knuckles/ssr": "minor",
Expand Down
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default config([
"**/vite.config.*",
"**/jest.config.ts",
"**/coverage/",
"**/__fixtures__/",

// documentation
"docs/**/*",
Expand Down
8 changes: 4 additions & 4 deletions packages/analyzer/src/analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
type NormalizedConfig,
} from "@knuckles/config";
import { type ParserError, parse } from "@knuckles/parser";
import type { Document } from "@knuckles/syntax-tree";
import type { SyntaxTree } from "@knuckles/syntax-tree";
import assert from "node:assert";

export interface AnalyzerOptions {
Expand All @@ -26,15 +26,15 @@ export interface AnalyzeOptions {
}

export interface AnalyzeCache {
document?: Document;
document?: SyntaxTree;
snapshots?: Partial<AnalyzerSnapshots>;
}

export interface AnalyzeResult {
issues: AnalyzerIssue[];
snapshots: Partial<AnalyzerSnapshots>;
metadata: Record<string, unknown>;
document: Document | null;
document: SyntaxTree | null;
}

export class Analyzer {
Expand Down Expand Up @@ -102,7 +102,7 @@ export class Analyzer {
const snapshots = (options?.cache?.snapshots ?? {}) as AnalyzerSnapshots;
const metadata = {};

let document: Document;
let document: SyntaxTree;
if (options?.cache?.document) {
document = options.cache.document;
} else {
Expand Down
13 changes: 12 additions & 1 deletion packages/analyzer/src/issue.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Position } from "@knuckles/location";
import type { Position, Range } from "@knuckles/location";

export enum AnalyzerSeverity {
Error = "error",
Expand All @@ -11,4 +11,15 @@ export interface AnalyzerIssue {
message: string;
start: Position | undefined;
end: Position | undefined;
quickFix?: AnalyzerQuickFix | undefined;
}

export interface AnalyzerQuickFix {
label?: string | undefined;
edits: AnalyzerQuickFixEdit[];
}

export interface AnalyzerQuickFixEdit {
range: Range;
text: string;
}
4 changes: 2 additions & 2 deletions packages/analyzer/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { AnalyzerIssue } from "./issue.js";
import type { NormalizedConfig } from "@knuckles/config";
import type { Snapshot } from "@knuckles/fabricator";
import type { Document } from "@knuckles/syntax-tree";
import type { SyntaxTree } from "@knuckles/syntax-tree";

export interface AnalyzerSnapshots {
[name: string]: Snapshot | undefined;
Expand All @@ -12,7 +12,7 @@
export interface AnalyzeContext {
readonly fileName: string;
readonly text: string;
readonly document: Document;
readonly document: SyntaxTree;
readonly snapshots: AnalyzerSnapshots;
readonly metadata: Record<string, unknown>;

Expand All @@ -20,7 +20,7 @@
}

export interface AnalyzerFlags {
tsconfig?: any;

Check warning on line 23 in packages/analyzer/src/plugin.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
}

export interface InitializeContext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ export default {
check({ report, document }) {
document.visit(
(node): void => {
const regex = new RegExp(
`\\/ko\\s+${escapeStringRegexp(node.binding.name.value)}`,
);
const bindingName = node.binding.name.value;
const regex = new RegExp(`\\/ko\\s+${escapeStringRegexp(bindingName)}`);

if (!regex.test(node.endComment.content)) {
report({
Expand All @@ -21,6 +20,15 @@ export default {
severity: this.severity,
start: node.endComment.start,
end: node.endComment.end,
quickFix: {
label: "Add notation",
edits: [
{
range: node.endComment,
text: `<!-- /ko ${bindingName} -->`,
},
],
},
});
}
},
Expand Down
4 changes: 2 additions & 2 deletions packages/analyzer/src/standard/transpile.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Chunk } from "@knuckles/fabricator";
import {
type Document,
type SyntaxTree,
Element,
type Binding,
KoVirtualElement,
} from "@knuckles/syntax-tree";

export function transpile(document: Document) {
export function transpile(document: SyntaxTree) {
const chunk = new Chunk();

const render = (binding: Binding) => {
Expand Down
6 changes: 0 additions & 6 deletions packages/language-server/jest.config.ts

This file was deleted.

10 changes: 0 additions & 10 deletions packages/language-server/project.json

This file was deleted.

54 changes: 0 additions & 54 deletions packages/language-server/src/features/diagnostics.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/language-server/src/index.ts

This file was deleted.

41 changes: 0 additions & 41 deletions packages/language-server/src/language-server.ts

This file was deleted.

76 changes: 0 additions & 76 deletions packages/language-server/src/language-service.ts

This file was deleted.

7 changes: 0 additions & 7 deletions packages/language-server/tsconfig.json

This file was deleted.

4 changes: 0 additions & 4 deletions packages/language-server/tsconfig.lib.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<!--
---
name: language-server
name: language-service
---
-->

# Language Server

<!-- @include docs/parts/packages/language-server/description.md-->
<!-- @include docs/parts/packages/language-service/description.md-->

Implements a language server according to the [Language Server Protocol] (LSP) to provide language features for [Knockout] views.

<!-- /include -->

<!-- @include docs/parts/package-nav.md -->

[**Documentation**](https://knuckles.elsk.dev) | [Package (npm)](https://npmjs.com/package/@knuckles/language-server) | [Repository](https://github.com/tscpp/knuckles) | [Source Code](https://github.com/tscpp/knuckles/tree/main/packages/language-server)
[**Documentation**](https://knuckles.elsk.dev) | [Package (npm)](https://npmjs.com/package/@knuckles/language-service) | [Repository](https://github.com/tscpp/knuckles) | [Source Code](https://github.com/tscpp/knuckles/tree/main/packages/language-service)

<!-- /include -->

Expand Down
6 changes: 6 additions & 0 deletions packages/language-service/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable */
export default {
displayName: "@knuckles/language-service",
preset: "../../jest.preset.cjs",
coverageDirectory: "../../coverage/packages/language-service",
};
Loading
Loading