Compare commits
No commits in common. "e4bdddc762e66b8290a847c79252c3f6c8def20f" and "1fec471da98da62a6b3c815236c085af1b208fa4" have entirely different histories.
e4bdddc762
...
1fec471da9
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -35,5 +35,3 @@ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
|
|||
|
||||
/tmp
|
||||
/docs
|
||||
|
||||
*.vsix
|
||||
4
vscode-extension/.gitignore
vendored
Normal file
4
vscode-extension/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
node_modules
|
||||
client/dist
|
||||
server/dist
|
||||
*.vsix
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
import { TextDocument, Position } from 'vscode-languageserver-textdocument'
|
||||
import { Diagnostic, DiagnosticSeverity } from 'vscode-languageserver/node'
|
||||
import { Tree } from '@lezer/common'
|
||||
import { parser } from '../../../src/parser/shrimp'
|
||||
import { Compiler } from '../../../src/compiler/compiler'
|
||||
import { CompilerError } from '../../../src/compiler/compilerError'
|
||||
|
||||
export const buildDiagnostics = (textDocument: TextDocument, tree: Tree): Diagnostic[] => {
|
||||
export const buildDiagnostics = (textDocument: TextDocument): Diagnostic[] => {
|
||||
const text = textDocument.getText()
|
||||
const diagnostics = getParseErrors(textDocument, tree)
|
||||
const diagnostics = getParseErrors(textDocument)
|
||||
|
||||
if (diagnostics.length > 0) {
|
||||
return diagnostics
|
||||
|
|
@ -59,7 +59,9 @@ const unknownDiagnostic = (message: string): Diagnostic => {
|
|||
return diagnostic
|
||||
}
|
||||
|
||||
const getParseErrors = (textDocument: TextDocument, tree: Tree): Diagnostic[] => {
|
||||
const getParseErrors = (textDocument: TextDocument): Diagnostic[] => {
|
||||
const tree = parser.parse(textDocument.getText())
|
||||
|
||||
const ranges: { start: Position; end: Position }[] = []
|
||||
tree.iterate({
|
||||
enter(n) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { parser } from '../../../src/parser/shrimp'
|
||||
import * as Terms from '../../../src/parser/shrimp.terms'
|
||||
import { SyntaxNode, Tree } from '@lezer/common'
|
||||
import { SyntaxNode } from '@lezer/common'
|
||||
import { TextDocument } from 'vscode-languageserver-textdocument'
|
||||
import {
|
||||
SemanticTokensBuilder,
|
||||
|
|
@ -28,7 +28,9 @@ export const TOKEN_MODIFIERS = [
|
|||
SemanticTokenModifiers.readonly,
|
||||
]
|
||||
|
||||
export function buildSemanticTokens(document: TextDocument, tree: Tree): number[] {
|
||||
export function buildSemanticTokens(document: TextDocument): number[] {
|
||||
const text = document.getText()
|
||||
const tree = parser.parse(text)
|
||||
const builder = new SemanticTokensBuilder()
|
||||
const scopeTracker = new EditorScopeAnalyzer(document)
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import { PRELUDE_NAMES } from './metadata/prelude-names'
|
|||
import { parser } from '../../../src/parser/shrimp'
|
||||
import { setGlobals } from '../../../src/parser/tokenizer'
|
||||
import { Compiler } from '../../../src/compiler/compiler'
|
||||
import { Tree } from '@lezer/common'
|
||||
import {
|
||||
InitializeResult,
|
||||
TextDocuments,
|
||||
|
|
@ -15,10 +14,7 @@ import {
|
|||
createConnection,
|
||||
ProposedFeatures,
|
||||
CompletionItemKind,
|
||||
TextDocumentChangeEvent,
|
||||
} from 'vscode-languageserver/node'
|
||||
import { setGlobals } from '../../../src/parser/tokenizer'
|
||||
import { globals } from '../../../src/prelude'
|
||||
|
||||
// Initialize parser with prelude globals so it knows dict/list/str are in scope
|
||||
setGlobals(PRELUDE_NAMES)
|
||||
|
|
@ -27,16 +23,12 @@ const connection = createConnection(ProposedFeatures.all)
|
|||
const documents = new TextDocuments(TextDocument)
|
||||
documents.listen(connection)
|
||||
|
||||
const documentTrees = new Map<string, Tree>()
|
||||
|
||||
// Server capabilities
|
||||
connection.onInitialize(handleInitialize)
|
||||
|
||||
// Language features
|
||||
connection.languages.semanticTokens.on(handleSemanticTokens)
|
||||
documents.onDidOpen(handleDocumentOpen)
|
||||
documents.onDidChangeContent(handleDocumentChange)
|
||||
documents.onDidClose(handleDocumentClose)
|
||||
connection.onCompletion(handleCompletion)
|
||||
connection.onSignatureHelp(handleSignatureHelp)
|
||||
|
||||
|
|
@ -47,7 +39,10 @@ connection.onRequest('shrimp/bytecode', handleBytecode)
|
|||
// Start listening
|
||||
connection.listen()
|
||||
|
||||
// ============================================================================
|
||||
// Handler implementations
|
||||
// ============================================================================
|
||||
|
||||
function handleInitialize(): InitializeResult {
|
||||
connection.console.log('🦐 Server initialized with capabilities')
|
||||
const result: InitializeResult = {
|
||||
|
|
@ -72,42 +67,22 @@ function handleInitialize(): InitializeResult {
|
|||
return result
|
||||
}
|
||||
|
||||
function handleDocumentOpen(event: TextDocumentChangeEvent<TextDocument>) {
|
||||
const document = event.document
|
||||
setGlobals(Object.keys(globals))
|
||||
const tree = parser.parse(document.getText())
|
||||
documentTrees.set(document.uri, tree)
|
||||
}
|
||||
|
||||
function handleSemanticTokens(params: any) {
|
||||
const document = documents.get(params.textDocument.uri)
|
||||
if (!document) return { data: [] }
|
||||
|
||||
const tree = documentTrees.get(params.textDocument.uri)
|
||||
if (!tree) return { data: [] }
|
||||
|
||||
const data = buildSemanticTokens(document, tree)
|
||||
const data = buildSemanticTokens(document)
|
||||
return { data }
|
||||
}
|
||||
|
||||
function handleDocumentChange(change: TextDocumentChangeEvent<TextDocument>) {
|
||||
const document = change.document
|
||||
|
||||
// Parse and cache
|
||||
setGlobals(Object.keys(globals))
|
||||
const tree = parser.parse(document.getText())
|
||||
documentTrees.set(document.uri, tree)
|
||||
|
||||
// Build diagnostics using cached tree
|
||||
const diagnostics = buildDiagnostics(document, tree)
|
||||
connection.sendDiagnostics({ uri: document.uri, diagnostics })
|
||||
}
|
||||
|
||||
function handleDocumentClose(event: TextDocumentChangeEvent<TextDocument>) {
|
||||
documentTrees.delete(event.document.uri)
|
||||
function handleDocumentChange(change: any) {
|
||||
const textDocument = change.document
|
||||
const diagnostics = buildDiagnostics(textDocument)
|
||||
connection.sendDiagnostics({ uri: textDocument.uri, diagnostics })
|
||||
}
|
||||
|
||||
function handleCompletion(params: any) {
|
||||
console.log(`🌭 YOU ARE COMPLETING at position`, params.position)
|
||||
const document = documents.get(params.textDocument.uri)
|
||||
if (!document) {
|
||||
console.log('❌ No document found')
|
||||
|
|
@ -123,10 +98,7 @@ function handleCompletion(params: any) {
|
|||
const contextCompletions = provideCompletions(document, position)
|
||||
console.log(`🎯 Context completions count: ${contextCompletions.length}`)
|
||||
if (contextCompletions.length > 0) {
|
||||
console.log(
|
||||
`✅ Returning ${contextCompletions.length} completions:`,
|
||||
contextCompletions.map((c) => c.label).join(', ')
|
||||
)
|
||||
console.log(`✅ Returning ${contextCompletions.length} completions:`, contextCompletions.map(c => c.label).join(', '))
|
||||
return contextCompletions
|
||||
}
|
||||
|
||||
|
|
@ -157,13 +129,8 @@ function handleParseTree(params: { uri: string }) {
|
|||
const document = documents.get(params.uri)
|
||||
if (!document) return 'Document not found'
|
||||
|
||||
const tree = documentTrees.get(params.uri)
|
||||
if (!tree) {
|
||||
connection.console.error(`🦐 No cached tree for ${params.uri}`)
|
||||
return 'No cached parse tree available'
|
||||
}
|
||||
|
||||
const text = document.getText()
|
||||
const tree = parser.parse(text)
|
||||
const cursor = tree.cursor()
|
||||
|
||||
let formatted = ''
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user