diff --git a/server/src/providers/linter/codeActions.ts b/server/src/providers/linter/codeActions.ts index 8b619c12..f4afc376 100644 --- a/server/src/providers/linter/codeActions.ts +++ b/server/src/providers/linter/codeActions.ts @@ -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 { @@ -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 ); diff --git a/server/src/providers/linter/index.ts b/server/src/providers/linter/index.ts index 0374b4e5..5aaa2d66 100644 --- a/server/src/providers/linter/index.ts +++ b/server/src/providers/linter/index.ts @@ -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; @@ -33,6 +34,8 @@ export function initialise(connection: _Connection) { delete jsonCache[validKey]; } + boundLintConfig = {}; + runLinter = true; } }); @@ -49,7 +52,7 @@ export function initialise(connection: _Connection) { } ).then(cache => { if (cache) { - refreshDiagnostics(document, cache); + refreshLinterDiagnostics(document, cache); } }); } @@ -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 = {} } }) } @@ -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); @@ -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; } @@ -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(); diff --git a/server/src/server.ts b/server/src/server.ts index 2d50bcda..00baa0e0 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -239,7 +239,7 @@ documents.onDidChangeContent(handler => { } ).then(cache => { if (cache) { - Linter.refreshDiagnostics(handler.document, cache); + Linter.refreshLinterDiagnostics(handler.document, cache); } }); });