Skip to content

Commit

Permalink
Merge pull request #19 from lfortran/dylon/symbol-and-error-types
Browse files Browse the repository at this point in the history
Adds support for using type symbol and diagnostic types from LFortran ...
  • Loading branch information
certik authored Dec 5, 2024
2 parents d1f3ccc + 50fdec8 commit cd96fb4
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 24 deletions.
15 changes: 8 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@
!*/

# Include specific file patterns
!/.github/workflows/*.yaml
!/.github/workflows/*.yml
!/.gitignore
!/.mocharc.json
!/.vscodeignore
!/README.md
!/client/package.json
!/client/src/*.ts
!/client/test/spec/**/*.ts
!/client/testFixture/*.txt
!/client/test/spec/**/*.ts
!/client/tsconfig.json
!/esbuild.js
!/eslint.config.mjs
!/.github/workflows/*.yaml
!/.github/workflows/*.yml
!/.gitignore
!/integ/spec/**/*.ts
!/integ/tsconfig.json
!/.mocharc.json
!/package.json
!/README.md
!/scripts/*.sh
!/server/package.json
!/server/src/*.ts
Expand All @@ -30,7 +29,9 @@
!/server/tsconfig.json
!/settings.json
!/tsconfig.json
!/.vscodeignore

# Exclude problematic file patterns
/.test-extensions
/lfortran
/**/*.bak
1 change: 1 addition & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ versions.txt
.vscode-test
out/integ
lfortran
lfortran.bak
17 changes: 14 additions & 3 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,19 @@ import tseslint from "typescript-eslint";

/** @type {import('eslint').Linter.Config[]} */
export default [
{files: ["**/*.{js,mjs,cjs,ts}"]},
{languageOptions: { globals: globals.browser }},
{
files: ["**/*.{js,mjs,cjs,ts}"]
},
{
languageOptions: {
globals: globals.browser
}
},
pluginJs.configs.recommended,
...tseslint.configs.recommended,
];
{
rules: {
"@typescript-eslint/no-namespace": "off"
}
}
];
10 changes: 3 additions & 7 deletions server/src/lfortran-accessors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ import {

import {
Diagnostic,
DiagnosticSeverity,
Location,
Position,
Range,
SymbolInformation,
SymbolKind,
TextEdit,
} from 'vscode-languageserver/node';

import {
ExampleSettings,
ErrorDiagnostics
ErrorDiagnostics,
} from './lfortran-types';

import which from 'which';
Expand Down Expand Up @@ -184,7 +182,7 @@ export class LFortranCLIAccessor implements LFortranAccessor {
settings: ExampleSettings): Promise<SymbolInformation[]> {
const flags = ["--show-document-symbols"];
const stdout = await this.runCompiler(settings, flags, text);
let results;
let results: SymbolInformation[];
try {
results = JSON.parse(stdout);
} catch (error) {
Expand All @@ -207,8 +205,6 @@ export class LFortranCLIAccessor implements LFortranAccessor {

const end: Position = range.end;
end.character--;

symbol.kind = SymbolKind.Function;
}
return symbols;
}
Expand Down Expand Up @@ -285,8 +281,8 @@ export class LFortranCLIAccessor implements LFortranAccessor {
const k = Math.min(results.diagnostics.length, settings.maxNumberOfProblems);
for (let i = 0; i < k; i++) {
const diagnostic: Diagnostic = results.diagnostics[i];
diagnostic.severity = DiagnosticSeverity.Warning;
diagnostic.source = "lfortran-lsp";
diagnostic.range.start.character--;
diagnostics.push(diagnostic);
}
}
Expand Down
37 changes: 34 additions & 3 deletions server/test/spec/lfortran-accessors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ describe("LFortranCLIAccessor", () => {
range: {
start: {
line: 0,
character: 10
character: 9
},
end: {
line: 2,
Expand All @@ -229,7 +229,7 @@ describe("LFortranCLIAccessor", () => {
range: {
start: {
line: 5,
character: 13
character: 12
},
end: {
line: 5,
Expand All @@ -244,7 +244,38 @@ describe("LFortranCLIAccessor", () => {
];

const stdout = JSON.stringify({
diagnostics: expected
diagnostics: [
{
range: {
start: {
line: 0,
character: 10
},
end: {
line: 2,
character: 20
}
},
severity: DiagnosticSeverity.Warning,
source: "lfortran-lsp",
message: "foo should be bar"
},
{
range: {
start: {
line: 5,
character: 13
},
end: {
line: 5,
character: 17
}
},
severity: DiagnosticSeverity.Warning,
source: "lfortran-lsp",
message: "baz should be qux"
},
]
});

sinon.stub(lfortran, "runCompiler").resolves(stdout);
Expand Down
42 changes: 38 additions & 4 deletions server/test/spec/lfortran-language-server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ import {

import { TextDocument } from "vscode-languageserver-textdocument";

import { ExampleSettings } from '../../src/lfortran-types';
import {
ExampleSettings,
} from '../../src/lfortran-types';

import { LFortranCLIAccessor } from "../../src/lfortran-accessors";

Expand Down Expand Up @@ -287,7 +289,7 @@ describe("LFortranLanguageServer", () => {
range: {
start: {
line: 0,
character: 10
character: 9
},
end: {
line: 2,
Expand All @@ -302,7 +304,7 @@ describe("LFortranLanguageServer", () => {
range: {
start: {
line: 5,
character: 13
character: 12
},
end: {
line: 5,
Expand All @@ -317,7 +319,39 @@ describe("LFortranLanguageServer", () => {
];

const stdout = JSON.stringify({
diagnostics: diagnostics
diagnostics: [
{
range: {
start: {
line: 0,
character: 10
},
end: {
line: 2,
character: 20
}
},
severity: DiagnosticSeverity.Warning,
source: "lfortran-lsp",
message: "foo should be bar"
},
{
range: {
start: {
line: 5,
character: 13
},
end: {
line: 5,
character: 17
}
},
// NOTE: Right now, the severity is hard-coded to Warning ...
severity: DiagnosticSeverity.Warning,
source: "lfortran-lsp",
message: "baz should be qux"
},
]
});
sinon.stub(lfortran, "runCompiler").resolves(stdout);
document.getText.returns("");
Expand Down

0 comments on commit cd96fb4

Please sign in to comment.