Skip to content

Commit

Permalink
Merge pull request #224 from halcyon-tech/fix/rpglint_config_file_fetch
Browse files Browse the repository at this point in the history
Fix for fetching lint config
  • Loading branch information
worksofliam authored Jun 13, 2023
2 parents b5e593f + 97c4fa1 commit 0083bcb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 deletions.
4 changes: 2 additions & 2 deletions server/src/providers/linter/codeActions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CodeAction, CodeActionParams, Range } from 'vscode-languageserver';
import { getActions, refreshDiagnostics } from '.';
import { getActions, refreshLinterDiagnostics } from '.';
import { documents, parser } from '..';

export default async function codeActionsProvider(params: CodeActionParams): Promise<CodeAction[]|undefined> {
Expand All @@ -13,7 +13,7 @@ export default async function codeActionsProvider(params: CodeActionParams): Pro
const docs = await parser.getDocs(document.uri);

if (docs) {
const detail = await refreshDiagnostics(document, docs, false);
const detail = await refreshLinterDiagnostics(document, docs, false);
if (detail) {
const fixErrors = detail.errors.filter(error => range.start.line === error.range.start.line );

Expand Down
44 changes: 38 additions & 6 deletions server/src/providers/linter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function initialise(connection: _Connection) {
connection.onCodeAction(codeActionsProvider);
connection.onDocumentFormatting(documentFormattingProvider);

// This only works for local workspace files
watchedFilesChangeEvent.push((params: DidChangeWatchedFilesParams) => {
let runLinter = false;

Expand All @@ -33,6 +34,8 @@ export function initialise(connection: _Connection) {
delete jsonCache[validKey];
}

boundLintConfig = {};

runLinter = true;
}
});
Expand All @@ -49,7 +52,7 @@ export function initialise(connection: _Connection) {
}
).then(cache => {
if (cache) {
refreshDiagnostics(document, cache);
refreshLinterDiagnostics(document, cache);
}
});
}
Expand All @@ -58,12 +61,16 @@ export function initialise(connection: _Connection) {
});

documents.onDidOpen(async e => {
const uri = e.document.uri;
const uriString = e.document.uri;

const possibleUri = await getLintConfigUri(uri);
const uri = URI.parse(uriString);

if (possibleUri && jsonCache[possibleUri]) {
delete jsonCache[possibleUri];
// If we open a new RPGLE file that is remote
// we need to refresh the lint config so we can
// make sure it's the latest.
if ([`member`, `streamfile`].includes(uri.scheme)) {
boundLintConfig = {};
jsonCache = {}
}
})
}
Expand All @@ -83,10 +90,23 @@ export function calculateOffset(document: TextDocument, error: IssueRange) {
}
};

enum ResolvedState {
Found,
NotFound
};

let boundLintConfig: {[workingUri: string]: {resolved: ResolvedState, uri: string}} = {};

export async function getLintConfigUri(workingUri: string) {
const uri = URI.parse(workingUri);
let cleanString: string | undefined;

const cached = boundLintConfig[workingUri];

if (cached) {
return cached.resolved === ResolvedState.Found ? cached.uri : undefined;
}

switch (uri.scheme) {
case `member`:
const memberPath = parseMemberUri(uri.path);
Expand Down Expand Up @@ -123,6 +143,18 @@ export async function getLintConfigUri(workingUri: string) {
break;
}

if (cleanString) {
boundLintConfig[workingUri] = {
resolved: ResolvedState.Found,
uri: cleanString
}
} else {
boundLintConfig[workingUri] = {
resolved: ResolvedState.NotFound,
uri: ``
};
}

return cleanString;
}

Expand Down Expand Up @@ -150,7 +182,7 @@ export async function getLintOptions(workingUri: string) {
return result;
}

export async function refreshDiagnostics(document: TextDocument, docs: Cache, updateDiagnostics = true) {
export async function refreshLinterDiagnostics(document: TextDocument, docs: Cache, updateDiagnostics = true) {
const isFree = (document.getText(Range.create(0, 0, 0, 6)).toUpperCase() === `**FREE`);
if (isFree) {
const text = document.getText();
Expand Down
2 changes: 1 addition & 1 deletion server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ documents.onDidChangeContent(handler => {
}
).then(cache => {
if (cache) {
Linter.refreshDiagnostics(handler.document, cache);
Linter.refreshLinterDiagnostics(handler.document, cache);
}
});
});
Expand Down

0 comments on commit 0083bcb

Please sign in to comment.