Add methods to function from another module

Hi everyone,

I have a module A that simply define a function

module A

"""
    f(config::ConnectionConfiguration)
    Connects to the database using the given configuration.
"""
function connect end
end

Now from module B I’m trying to add new methods to that function doing something like that

module B
using A

A.connect(config::SQLiteConnectionConfiguration) = SQLite.DB(config.dbname)
end

At these point everything works fine but I got a warning message from vscode extension in module B saying

A.connect is a Function . 0 methods for function A.connect

Then I need to use these two modules in my application so I do

using A
using B

A.connect(config)

Here I got another warning message from vscode extension saying the same thing

A.connect is a Function . 0 methods for function A.connect

Both A and B are packages.
Note that everything is working fine. The main problem seems to be the vscode extension the is not able to find the methods implementation and having a lot of warning and not be able to use autocomplete is not good.
In my application I don’t want to use B.connect since I could have also C, D and so on that implements new methods and i want to use the dispatch.

How can I solve those issues? Is this the right thing to do?

you need import A instead

Hi @jling thanks for pointing it out. I tried using import instead. I still has warnings in module B (that extends functions in module A) but I don’t have anymore warnings in the applications that uses it.

I’m doing something like

module A

"""
    mapping(db::Type{S}, t::Type{T})::String where {S,T}
    Returns the mapping for the given database and type
"""
function mapping end

end

Then in module B

module B

import A
using SQLite

A.mapping(db::Type{SQLite.DB}, t::Type{Int64})::String = "INTEGER"

end

vscode returns “Possible method call error”.

Also I wanted to ask what is the real difference here between import and using because from documentation Modules · The Julia Language you can use both using and import to add methods using module path.