Skip to content

Commit

Permalink
fix: content of function wasn't refreshed
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNuclearNexus committed Sep 26, 2024
1 parent b7a9a68 commit 8657b53
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 27 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ on:

jobs:
build:
runs-on: ${{ matrix.os }}
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]


steps:
- uses: actions/checkout@v2
Expand All @@ -44,4 +41,4 @@ jobs:
uses: actions/[email protected]
with:
path: 'extension/*.vsix'
name: extension-${{matrix.os}}
name: extension
4 changes: 3 additions & 1 deletion language_server/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ def create_context(config: ProjectConfig, config_path: Path) -> Context:

for location, file in pack.all():
try:
PATH_TO_RESOURCE[str(file.ensure_source_path())] = (location, file)
path = file.ensure_source_path()
logging.debug(path)
PATH_TO_RESOURCE[str(path)] = (location, file)
except:
continue

Expand Down
48 changes: 27 additions & 21 deletions language_server/server/features/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,18 @@

from language_server.server.indexing import Indexer

from .. import COMPILATION_RESULTS, PATH_TO_RESOURCE, CompiledDocument, MechaLanguageServer


def validate(ls: MechaLanguageServer, params: lsp.DidOpenTextDocumentParams|lsp.DidChangeTextDocumentParams):
from .. import (
COMPILATION_RESULTS,
PATH_TO_RESOURCE,
CompiledDocument,
MechaLanguageServer,
)


def validate(
ls: MechaLanguageServer,
params: lsp.DidOpenTextDocumentParams | lsp.DidChangeTextDocumentParams,
):
text_doc = ls.workspace.get_document(params.text_document.uri)
ctx = ls.get_context(text_doc)

Expand Down Expand Up @@ -69,32 +77,34 @@ def validate_function(
) -> list[InvalidSyntax]:
logging.debug(f"Parsing function:\n{text_doc.source}")
logging.debug(text_doc.path)
for pack in ctx.packs:
for path, file in pack.all():
logging.debug(f"{path}: {file.ensure_source_path()}")

if text_doc.path not in PATH_TO_RESOURCE:
COMPILATION_RESULTS[text_doc.uri] = CompiledDocument(
ctx, "", None, [], None, None
)
return []

location, file = PATH_TO_RESOURCE[text_doc.path]

if not isinstance(file, Function) and not isinstance(file, Module):
COMPILATION_RESULTS[text_doc.uri] = CompiledDocument(
ctx,
location,
None,
[],
None,
None
ctx, location, None, [], None, None
)
return []

# file.text = text_doc.source

compiled_doc = parse_function(ctx, location, file)
# file.set_content(text_doc.source)

compiled_doc = parse_function(ctx, location, type(file)(text_doc.source, text_doc.path))

COMPILATION_RESULTS[text_doc.uri] = compiled_doc

return compiled_doc.diagnostics


def parse_function(
ctx: Context, location: str, function: Function|Module
ctx: Context, location: str, function: Function | Module
) -> CompiledDocument:
mecha = ctx.inject(Mecha)

Expand Down Expand Up @@ -130,25 +140,21 @@ def parse_function(
if isinstance(node, AstError):
diagnostics.append(node.error)


if len(diagnostics) == 0:
runtime = ctx.inject(Runtime)
compiled_module = runtime.modules.get(function)

if compiled_module is not None:
compiled_module.ast = indexer(compiled_module.ast)
logging.debug(compiled_module)
else:
compiled_module = None




return CompiledDocument(
resource_location=location,
ast=ast,
diagnostics=diagnostics,
compiled_unit=compiled_unit,
compiled_module=compiled_module,
ctx=ctx
ctx=ctx,
)

0 comments on commit 8657b53

Please sign in to comment.